- #1
yungman
- 5,755
- 293
I encountered a strange error. I have 2 EXACTLY same code in this program, I just use /* */ to disable one or the other. The bottom one works, the top one giving me error. I literally copied the content inside main() from the bottom to the top, still, the top one fails and bottom works.
If I missed anything, I must be really blind. Like I said, I copied the content inside main() from bottom to the top, still have problem.
The error is :
And when I choose run anyway, the error is:
I did closed the VS and start over, also, I clean Build solution every time also. Also, I printed the code out and compared word by word. Can you see why?
thanks
C++:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
main()
{
fstream dataFile;
dataFile.open("C:\\Users\\alanr\\Desktop\\C++ exercise\
\\Gaddis\\inout files\\demofile.txt", ios::out | ios::app);
dataFile << " Lucky " << " Chicky\n\n" << " Slave " << " Rooster\n\n";
dataFile.close();
return 0;
}
/*#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
fstream dataFile;
dataFile.open("C:\\Users\\alanr\\Desktop\\C++ exercise\
\\Gaddis\\inout files\\demofile.txt", ios::out|ios::app);
dataFile << " Lucky " << " Chicky\n\n" << " Slave " << " Rooster\n\n";
dataFile.close();
return 0;
}*/
If I missed anything, I must be really blind. Like I said, I copied the content inside main() from bottom to the top, still have problem.
The error is :
And when I choose run anyway, the error is:
I did closed the VS and start over, also, I clean Build solution every time also. Also, I printed the code out and compared word by word. Can you see why?
thanks
Last edited: