C++ NOTEPAD ERROR

Mar 18, 2014 at 9:41am
I HAVE A PROGRAM THAT I CONNECTED TO NOTEPAD. IT WORKED BUT THE OUTPUT ON MY PROGRAM CAN'T DISPLAY ON NOTEPAD. NOTEPAD JUST DISPLAY QUESTION MARK '?'. HERE'S MY CODE.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    string name;
    int right =10;
    cout<<" Enter your name: ";
     cin>>name;
     cout<<endl<<endl;  
     cout<<" Your name is "<<name <<" and your score is "<<right<<endl<<endl;

     ofstream MyScore ("myscore.txt");
     MyScore << name <<"      " <<right;
     MyScore.close ();
    system("PAUSE");
    return EXIT_SUCCESS;
}
Mar 18, 2014 at 9:44am
Try ending the text file with a newline character.
 
MyScore << name << "      " << right << '\n';

Mar 18, 2014 at 9:48am
still the same. the notepad displayed ?. Is there a problem on my code? or it just my notepad? But a few days ago it worked.
Mar 18, 2014 at 10:00am
What do you exactly mean when you say that your program is connected to notepad? Do you run the program and then you open myscore.txt in notepad?
Mar 18, 2014 at 10:14am
Yes.
Mar 18, 2014 at 11:22am
Does the name that you enter contain any special character or just plain ASCII?
Mar 18, 2014 at 11:40am
I clicked the unicode controls etc.
Mar 18, 2014 at 11:43am
Where? Notepad does not support unicode as far as I know (at least in XP it didn't).
Mar 18, 2014 at 11:45am
I mean I clicked unicode control character on my notepad. I saved it as ANSI (?)
Mar 18, 2014 at 11:52am
Does it work if you use a name that consists of pure ASCII characters (like "Cassie")?

Are you sure you are looking at the correct file?

Are you sure the file is opened correctly? On Windows it can fail to open the file if some other program has opened the file already. Put something like this right after line 17 to make sure.
1
2
3
4
if (!MyScore)
{
	cout << "Error! Failed to open file." << endl;
}
Last edited on Mar 18, 2014 at 11:56am
Mar 18, 2014 at 12:06pm
It still question mark. But thanks a lot :)
Topic archived. No new replies allowed.