Is the std::string empty - or not?
If we check a string like this
std::string myStr;
if(myStr.empty())
std::cout << "The string is empty" << std::endl;
else
std::cout << "The string is not empty" << std::endl; It of course returns the first message, but if we do like this
for(int i = 0; i <= 50; i++)
{
if(static_cast<int>(myStr[i]) != 0)
std::cout << "Index[" << i << "] = " << static_cast<int>(myStr[i]) << std::endl;
} Then there's is some of them with content. On my computer I get the output
Quote:
|
Originally Posted by Output
Index[4] = 7
Index[8] = 8
Index[12] = 11
Index[16] = 6
Index[20] = 4
Index[24] = 5
Index[28] = 14
Index[32] = 3
Index[36] = 12
Index[40] = 13
Index[44] = 9
Index[48] = 10
|
As we can see it jumps four, before it's contains content, why?
How can I competely clear the string? I've tried clear() but it again returns some strange content. I've to clear the string competely, because I've to do actions like
myStr[2]++ on empty strings, and it's hard if it contains something...
// This is how it should be...
// myStr[4] = 0;
myStr[4]++;
// myStr[4] = 1;
// This is how it is now...
// myStr[4] = 7;
myStr[4]++;
// myStr[4] = 8;