Need help quickly,, string problem

can you correct the last line of this section of code???






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];

Score++;
char nScore[]="";
itoa(Score,nScore,10);
using std::string;
SetWindowText(hWndMain,WINDOWTITLE+ '-' + string nScore);
}

char nScore[]=""; This creates an array with 1 element. Make the array bigger to be able to store the number text representation
that doesnt seem to be the problem the problem is that i get an error that says "expected primary expression before "nScore" when compiling
string nScore this is not right
do you know the proper format?
It depends on what you are trying to do.

I guess you are trying to concatenate strings here.
WINDOWTITLE+ '-' + string nScore
if WINDOWTITLE is of type std::string it should be enough to write
WINDOWTITLE+ '-' + nScore
If WINDOWTITLE is a c string that will not work because operator+ doesn't work on c strings. What you can do is convert the first string to an std::string and everything will follow.
std::string(WINDOWTITLE) + '-' + nScore
If you don't want to use std::string at all you will have to use std::strcat but that is just more work so I don't show how to do that.
Last edited on
still have a compile error, your right about what im trying to do its just no working, i posted the code to codepad here http://codepad.org/tGnppb3G you can try to compile it, im using bloodshed dev c++
I don't have windows so I can't compile it but if SetWindowText takes a c string as argument you have to convert it to a c string.
SetWindowText(hWndMain,(std::string(WINDOWTITLE) + '-' + nScore + '-' + string nScore).c_str());
thanks ill try that, let you know if i have a problem later
eh still no good, i just dont get it, its supposed to be a scoring system based off of the RemoveRow() function

when using
SetWindowText(hWndMain, WINDOWTITLE + '-' + nScore);
i get
1176 invalid operands of types `const char*' and `char[1]' to binary `operator+'
Last edited on
WINDOWTITLE is a c string. You can't concatenate c strings with operator+
it works like this
SetWindowText(hWndMain, WINDOWTITLE + '-' //+(string)nScore);
so its a problem with the string function or nScore
Are you sure that works when you run it because I don't think it does. I realize I made a mistake in the code I posted earlier. Try this instead:
SetWindowText(hWndMain,(std::string(WINDOWTITLE) + '-' + nScore).c_str());

Last edited on
IT WORKS!!! THANK YOU SO MUCH!!!!!!!! OHMYGOD!!!! haha no really thanks
Topic archived. No new replies allowed.