Mega Code Archive

 
Categories / C++ Tutorial / Data Types
 

Using strlen

#include <iostream> using std::cout; using std::endl; #include <cstring> using std::strlen;                         int main() {    char *string1 = "asdfasdfasdfasdf";    char *string2 = "     f    ";    char *string3 = "       ";    cout << "The length of \"" << string1 << "\" is " << strlen( string1 )       << "\nThe length of \"" << string2 << "\" is " << strlen( string2 )       << "\nThe length of \"" << string3 << "\" is " << strlen( string3 )        << endl;    return 0; } The length of "asdfasdfasdfasdf" is 16 The length of " f " is 10 The length of " " is 7