Page 1 of 1

TTF High Scores Dilema

Posted: Mon Feb 01, 2010 2:18 am
by RandomDever
I'm currently working on a new project that I want to have a list of the top 5 high scores but ifstream objects seem to only be able to convert each line into a string.
However to print it to the screen I need it to be a char * so I don't know what to do.
And another more minor problem is that every time the program starts I want the highscores.txt file to be filled with fake scores but ONLY if it's empty, but I can't think of any way to check that.
Any and all help will be very appreciated.

Re: TTF High Scores Dilema

Posted: Mon Feb 01, 2010 3:24 am
by K-Bal
Look at the reference. They have a member function called c_str.

Re: TTF High Scores Dilema

Posted: Mon Feb 01, 2010 5:40 am
by RandomDever
Tried that already.

Re: TTF High Scores Dilema

Posted: Mon Feb 01, 2010 6:41 am
by Bakkon
RandomDever wrote:Tried that already.
Then it should work.

Code: Select all

string myString = "High Score";
TTF_RenderText_Solid(font, myString.c_str(), color);
Also, just have a bool named "makeFakeScores" or something, start it as true, if you find something in the high scores files, flip it to false.

Re: TTF High Scores Dilema

Posted: Mon Feb 01, 2010 7:17 am
by RandomDever
EDIT: Well I tried it and it works now..... For some reason. :| :)
But how do I check whether a text file is empty or not?
And how do you add two strings together with a space added to separate them?

Re: TTF High Scores Dilema

Posted: Mon Feb 01, 2010 8:13 am
by Bakkon
Have you tried reading any documentation?

http://www.cplusplus.com/reference/iostream/fstream/

peek() and see if it's empty.

Re: TTF High Scores Dilema

Posted: Mon Feb 01, 2010 8:19 am
by hurstshifter
Bakkon wrote:Have you tried reading any documentation?

Haha, this