944,050 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 21109
  • C++ RSS
Apr 3rd, 2006
0

how to find length of a string

Expand Post »
i want to find the length of a string but by using string.length() or string.size() well i don't really get the length of the string coz if i have a space well it won't read further. Eg "Hello world!!!" will return me 5 coz it will stop at the space. Can anyone help me on how i can find the length of a string???
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tsubasa is offline Offline
6 posts
since Apr 2006
Apr 3rd, 2006
0

Re: how to find length of a string

Inputting material into the string will stop at whitespace characters such as space if you use the << operator to assign the information, but the string can have whitespace char if you initialize the string or if you use something like getline(). Once the string variable has a information that has whitespace in it the whitespace should be counted by either strlen() for null terminated strings or length() for STL strings. This should help illustrate the point.

char str[20] = "hello world";
cout << strlen(str) << endl;

std::string str1 = "hello world";
cout << str1.length() << endl;
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Apr 3rd, 2006
0

Re: how to find length of a string

thanks a lot for your help!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tsubasa is offline Offline
6 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need help creating and terminating processes in C++
Next Thread in C++ Forum Timeline: Sound/song in this project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC