Hey I'm trying to get it to print numbers from this file and its printing weird smiley faces instead. This is all thats in the file:
9 0
3 5
6 1
3 6
8 1
5 3
2 5
8 0
7 1
8 1 0
I want it to print out "9-0 3-5 6-1" etc... but its printing weird black and white smileys in the place of the numbers. There are probably other errors in the code but this it the problem I'm worried about. Here's the code:
while(scores >> score[i])
I've never seen it done like that. Does it really work? EDIT: I couldn't get it to compile. Could be C++11 I suppose.
To answer your question:
When you do something like this: game += (2*1); you are actually just adding a character to the string equivalent to an ascii code.
If you want to output a number and not the ascii equivalent of that number then use a stringstream instead. This will format integers, floats, anything into a string automatically:
1 2 3 4 5 6 7 8 9 10
string scorer(int score[], int NUMSCORES){
stringstream game;
for(int i=0;i<NUMSCORES;i++){
game << score[i*2];
game << "-";
game << score[i*2+1];
game << "\t";
}
return game.str();
}
Edit: I forgot to mention. Replace #include <string> with #include <stringstream>