May 31, 2014 at 10:40pm May 31, 2014 at 10:40pm UTC
1 2 3 4 5 6 7
ofstream myFile;
string file;
cout << "Save as: " ;
cin >> file;
myFile.open(file.c_str());
// Do stuff
myFile.close();
That's how I do it.
EDIT:
I took 'output' the wrong way.
1 2 3 4 5 6 7 8 9 10 11 12 13
ifstream myFile;
string file;
cout << "Open file: " ;
cin >> file;
myFile.open(file.c_str());
if (myFile.is_open())
{
// Get contents from file
}
else
{
cout << "\nCould not open file: " << file << "\n\n" ;
}
Last edited on May 31, 2014 at 10:45pm May 31, 2014 at 10:45pm UTC
May 31, 2014 at 10:56pm May 31, 2014 at 10:56pm UTC
Thanks but
I have the file opened and I used the data in the file but I don't know how to then take what I wrote and output the file with the stuff I wrote.
Last edited on May 31, 2014 at 11:00pm May 31, 2014 at 11:00pm UTC
May 31, 2014 at 11:07pm May 31, 2014 at 11:07pm UTC
You mean display what is in the file? or to store it in an array or something?
May 31, 2014 at 11:12pm May 31, 2014 at 11:12pm UTC
currently I have the "test" file being stored in an array. So I added all the numbers together and I want to output the sum of those nmbers to a new file on my pc.
I hope I am making sense
Jun 1, 2014 at 12:47am Jun 1, 2014 at 12:47am UTC
What does this mean
myFile.open(file.c_str());
also I was using ifstream for my prgram. So When I changed ifstream to ofstream, this symbol << was underlined red.
Last edited on Jun 1, 2014 at 12:49am Jun 1, 2014 at 12:49am UTC