[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppStrlen

(C++) std::strlen

Standard function to get the length of a char* (a C-style or null-terminated string) not including the \0 terminator.

  1. include <cstring>
  2. include <iostream>
int main() { const char * const myString = "Bilderbikkel"; const int length = std::strlen(myString); std::cout << "Length is " << length << std::endl; }


It is similar to the std::string::size method of a std::string. The code below shows this:

  1. include <cstring>
  2. include <string>
  3. include <cassert>
int main() { const std::string myString = "Bilderbikkel"; const int lengthCppStyle = myString.size(); const int lengthCstyle = std::strlen(myString.c_str()); assert(lengthCstyle == lengthCppStyle); }


Use std::string instead of an array of char [1,2].

Code links

Reference



last edited (March 29, 2007) by bilderbikkel, Number of views: 940, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.