Hi, I've got a very simple but annoying problem. I've used google, I've searched other C++ forums, but I haven't found a solution.
1 2 3
if (letter3=="\n"){
letter3==letter;
PrintCharacterLineEnd();
This is a code. the string "letter3" contains the string "\n". What I want to happen is when, letter3 contains the text "\n" I want to go to the function PrintCharacterLineEnd.
if letter3 don't contain "\n" (eg. some 4294967295 like borland 5 or some -1 ) & we use it directly in 'if()'
so I suggest this :
1 2 3 4 5 6 7 8
int test = -1; // -1 means not containing & othetwise test is locaition of '\n' in our string
std::string letter, letter3 ;
//some actions on strings
test = letter3.find("\n");
if ( test >= 0 ) { //or test != -1
letter3 = letter;
PrintCharacterLineEnd();
}
As string:find returns an unsigned integer value, the value will always be greater than or equal to zero.
And while I'm here...
string::compare returns an int -- you should not be comparing it against bool true or false. You usually compare it against 0 as the method returns:
* -1 if the lhs is lexically of a lesser value than the rhs
* 0 if they're equal
*1 if the lhs is less than the rhs
I think letter is a char and letter3 is a string so that is why he can't assign the string to the char. Maybe be he meant letter3[3] = letter; but I could be very well wrong.