C ++ string: C style string

xiaoxiao2021-03-06  39

C primer notes.

Support two strings: C style string and String type introduced by ANSI C

C style string, use char * pointer to manipulate

The standard C library provides a set of functions for operation, such as:

Int strlen; const char *);

INT strcmp (const char *, const char *);

Char * STRCPY (Char *, const char *);

Related header files: #include

There are two representation of the C style string length of 0, and the corresponding pointer is 0: char * PCH = 0; or point to the empty string: char * pch = "

/ ******* CSTR.cpp ******* / # include using namespace std; const char * st = "the expense of spirit / n";

INT main (int Argc, char * argv []) {int LEN = 0; const char * p = st;

While (* p ) Len;

COUT << LEN << ":" << ST << end1; return 0;} / ********* * end of the .cpp file ********* /

Compilation: g -o cstr cstr.cpp

Run: cstr.exe

Output results:

22: The Expense of Spirit

转载请注明原文地址:https://www.9cbs.com/read-118515.html

New Post(0)