| | |
how to find length of a string
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2006
Posts: 6
Reputation:
Solved Threads: 0
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???
•
•
Join Date: Jul 2005
Posts: 1,707
Reputation:
Solved Threads: 275
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;
char str[20] = "hello world";
cout << strlen(str) << endl;
std::string str1 = "hello world";
cout << str1.length() << endl;
![]() |
Similar Threads
- aray or string (C++)
- converting from string to char* (C)
- vector<string> - way to find longest string? (C++)
- UNIX: _vscprintf not compiling (C)
- Return Length of a string? (C++)
Other Threads in the C++ Forum
- Previous Thread: Need help creating and terminating processes in C++
- Next Thread: Sound/song in this project
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






