Win32 app problem.

Pages: 12
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
closed account (1vRz3TCk)
Is the brace on the end of line 7 a typo or the cause of your problem?
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
it was a problem but it still didn't fix anything.
can i be using fstream in a win32 app?
Last edited on
closed account (1vRz3TCk)
It would be handy if you said what the error is....
(you have a semicolon missing on line 6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int Score=1;

BOOL SetWindowText(HWND hWnd,LPCTSTR lpString);

void RemoveRow(int row)

{

int x,y;

int counter=0;



for(x=0; x< MAPWIDTH; x++)

for(y=row; y>0; y--)

Map[x][y]=Map[x][y-1];
#include <windows.h>
Score++;
char nScore[]="";
itoa(Score,nScore,10);
using std::string;
    SetWindowText(hWndMain,(std::string(WINDOWTITLE) + " - " + "Score: " + nScore).c_str());
                               
#include <fstream>

{
using namespace std;
      ofstream.outputFile;
      outputFile.open ("hiscore.txt")
      outputFile << nScore;
      outputFile.close(); 
      }


to give an example of whats going on
closed account (1vRz3TCk)
Eeek! <the sound of someone running for the hills>
I know i Know its messy but its a poorly made game of Tetris and this is supposed to be the highscore function
This line 'ofstream.outputFile;' is wrong. Fix it.
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
1
2
3
4
5
6
7
8
9
#include <fstream>
using namespace std;
void hiscore()
{
      ofstream outputFile;
      outputFile.open ("hiscore.txt");
      outputFile << nScore;
      outputFile.close(); 
 }
really?? it cares where using namespace std; goes?
if someone wants to teamview me and help me fix it let me know
If you put using namespace std; inside a function it will only affect the code in that function.
yea, still didn't fix it thats why i asked if someone wants to teamview me
You keep writing code like this
1
2
3
#include <fstream>
{
	...

Is this really your code? Why did you remove int main () that you had in the earlier code.
http://pastebin.com/aq8EXrJQ

theres the full code for main, everything works but the hiscore function at the bottom
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.
Put function declarations outside functions and don't use #include inside functions. Better to put all the #include at the top of the file.
yea, but still no run, check out the pastebin
Pages: 12