Gerard-Meier

How to use strlen

Feb 19th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. // includes and usings
  2.  
  3. int main() {
  4.    
  5.     char * cstring = new char[6];
  6.     cstring[0] = 'H';
  7.     cstring[1] = 'E';
  8.     cstring[2] = 'L';
  9.     cstring[3] = 'L';
  10.     cstring[4] = 'O';
  11.     cstring[5] = '!';
  12.  
  13.     // Depending on cosmic radiation, this may work every other year.
  14.     cout << "lenght: " << strlen(cstring) << endl;
  15.  
  16.     // Add the null byte to the end:
  17.     cstring[5] = '\0';
  18.  
  19.     // Point in case.
  20.     cout << "lenght: " << strlen(cstring) << endl;
  21.    
  22.     // Wait until the user figures out that "enter" closes the window.
  23.     return cin.get();
  24. }
Advertisement
Add Comment
Please, Sign In to add comment