G
Gactimus
I wrote a C++ program that is supposed to copy one text file to another.
It works fine if I specify the files to be opened and copied but when I
try to have the file names inputted by the user it doesn't work and I am
stumped. Can anyone clue me in to what I am missing?
Here is my code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string source;
string clone;
cout << "Enter the source file: ";
cin >> source;
cout << "Enter the name of the new file: ";
cin >> clone;
ifstream in(source.c_str); // Open for reading
ofstream out(clone.c_str); // Open for writing
string s;
while(getline(in, s))
out << s << "\n";
return 0;
}
It works fine if I specify the files to be opened and copied but when I
try to have the file names inputted by the user it doesn't work and I am
stumped. Can anyone clue me in to what I am missing?
Here is my code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string source;
string clone;
cout << "Enter the source file: ";
cin >> source;
cout << "Enter the name of the new file: ";
cin >> clone;
ifstream in(source.c_str); // Open for reading
ofstream out(clone.c_str); // Open for writing
string s;
while(getline(in, s))
out << s << "\n";
return 0;
}