Hi all
This is my first post in this forum
.
Im a student learning C++ and i have run into a wall when trying to write to a text file.
its a simple code but seems that it has issues. can anyone take a look at it and tell me what i have done wrong?
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("C:\Users\Me\Documents\Visual Studio 2008\Projects\filewrite\test.txt");
if(!out) {
cout << "Cannot open file.\n";
return 1;
}
out << 10 << " " << 123.23 << endl;
out << "This is a short text file.";
out.close();
return 0;
}
I have created a textfile called test.txt in the folder specified above. do i have to do some project properties changing in VS2008 too?
cos when i run the program it says the following.
"cannot open file"
thanks
PS: i have tried many other writing to file codes i have found online and they give similar errors.