Dec 5, 2011 at 4:43pm UTC
this piece of code causes an error
1 2 3 4 5 6 7 8 9 10
#include <fstream>
{
using namespace std;
ofstream.outputFile;
outputFile.open ("hiscore.txt" )
if (outputFile.is_open()}
outputFile << nScore;
outputFile.close();
}
gives the errors
here,, and a ton more
http://ScrnSht.com/guvanx
Last edited on Dec 5, 2011 at 4:46pm UTC
Dec 5, 2011 at 4:46pm UTC
Is the brace on the end of line 7 a typo or the cause of your problem?
Dec 5, 2011 at 4:49pm UTC
If that's what your code looks like, you should read a tutorial. If this is a crude combination of several snippets of your code, post a less messy version.
Last edited on Dec 5, 2011 at 4:49pm UTC
Dec 5, 2011 at 4:50pm UTC
it was a problem but it still didn't fix anything.
can i be using fstream in a win32 app?
Last edited on Dec 5, 2011 at 4:51pm UTC
Dec 5, 2011 at 4:53pm UTC
It would be handy if you said what the error is....
(you have a semicolon missing on line 6)
Dec 5, 2011 at 4:58pm UTC
Eeek! <the sound of someone running for the hills>
Dec 5, 2011 at 4:59pm UTC
I know i Know its messy but its a poorly made game of Tetris and this is supposed to be the highscore function
Dec 5, 2011 at 5:17pm UTC
This line 'ofstream.outputFile;' is wrong. Fix it.
Dec 5, 2011 at 5:33pm UTC
this by itself works fine
1 2 3 4 5 6 7 8 9 10
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt" );
myfile << "Writing this to a file.\n" ;
myfile.close();
return 0;
}
my code with this,
1 2 3 4 5 6 7 8
#include <fstream>
{
using namespace std;
ofstream outputFile;
outputFile.open ("hiscore.txt" );
outputFile << nScore;
outputFile.close();
}
won't work
Last edited on Dec 5, 2011 at 5:45pm UTC
Dec 5, 2011 at 6:01pm UTC
really?? it cares where using namespace std; goes?
Dec 5, 2011 at 6:02pm UTC
if someone wants to teamview me and help me fix it let me know
Dec 5, 2011 at 6:03pm UTC
If you put using namespace std;
inside a function it will only affect the code in that function.
Dec 5, 2011 at 6:04pm UTC
yea, still didn't fix it thats why i asked if someone wants to teamview me
Dec 5, 2011 at 6:11pm UTC
the int main part was an example for using ofstream on the tutorials on this site. the rest is variations of my code while trying to fix it.
Dec 5, 2011 at 6:11pm UTC
Put function declarations outside functions and don't use #include
inside functions. Better to put all the #include
at the top of the file.
Dec 5, 2011 at 6:25pm UTC
yea, but still no run, check out the pastebin