output file in VC++
-
Hi, I am trying to get a few parameters in an output file. i have included fsteam.h, and iostream.h my code is: ofstream out("output.txt"); CMyDoc* pDoc = GetDocument(); out<<"12454 "; out<X_Position<<"\n"; out<<"y: "; out<Y_Position<<"\n"; out<<"z: "; out<Z_Position<<"\n"; the code makes the output file, but its always empty,, any siggestions? Ehsan Behboudi
-
Hi, I am trying to get a few parameters in an output file. i have included fsteam.h, and iostream.h my code is: ofstream out("output.txt"); CMyDoc* pDoc = GetDocument(); out<<"12454 "; out<X_Position<<"\n"; out<<"y: "; out<Y_Position<<"\n"; out<<"z: "; out<Z_Position<<"\n"; the code makes the output file, but its always empty,, any siggestions? Ehsan Behboudi
- When is the file empty? Do you check while your program is running or afterwards? 2) Make sure you have
out.close();
after you finish. This is to make sure everything is output on the file.
Hosam Aly Mahmoud
- When is the file empty? Do you check while your program is running or afterwards? 2) Make sure you have
-
Hi, I am trying to get a few parameters in an output file. i have included fsteam.h, and iostream.h my code is: ofstream out("output.txt"); CMyDoc* pDoc = GetDocument(); out<<"12454 "; out<X_Position<<"\n"; out<<"y: "; out<Y_Position<<"\n"; out<<"z: "; out<Z_Position<<"\n"; the code makes the output file, but its always empty,, any siggestions? Ehsan Behboudi
First, the contents may be output to some file else if you use relative path like that, you better use absolute path to make sure the destination file is exactly which you expected. So type this instead:
ofstream out("C:\\output.txt");
. Second, you need to exam the stream first to make sure the destination file is ready to be written, so add this line right after you open it:ASSERT(out != NULL);
Third, always close a opened file as soon as you are done with it, add this line at the end:out.close();
I have a strong feeling that your problem was caused by the first issue, you probably will find "output.txt" in your "My Document" folder, lol.