As I am writing a cross-platform application, I want my code to work on both platforms.
In Windows, I use this code to compare 2 single characters.
for( int i = 0; i < str.size(); i++ )
if( str.substr( i, 1 ) == std::string( "¶" ) )
printf( "Found!\n" );
Now, in Linux, the character is not found. It is found when I change the substring to a length of 2.
for( int i = 0; i < str.size(); i++ )
if( str.substr( i, 2 ) == std::string( "¶" ) )
printf( "Found!\n" );
How do convert this character comparison code to be cross platform?
Solved using
str.compare()andsize()of character string: