Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 3rd, 2007, 6:02 AM   #1
v0id
Hobbyist Programmer
 
Join Date: Apr 2006
Posts: 155
Rep Power: 3 v0id is on a distinguished road
std::string is not empty?

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;
__________________
-- v0id
v0id is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
code check whether a folder is empty myName C++ 6 Jun 22nd, 2006 9:58 AM
Please Fix My Dll Kilo C++ 12 May 25th, 2006 12:21 PM
Testing for a palindrome using std::string Jessehk C++ 9 May 3rd, 2006 2:55 AM
empty array brad sue Other Programming Languages 3 Apr 22nd, 2006 9:48 PM
change the empty function from the old format to the new format powah Sed and Awk 0 Jun 23rd, 2005 12:10 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC