O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

char Arrays

A string is a series of characters. The only strings you've seen until now have been unnamed string constants used in cout statements, such as

cout << "hello world.\n";

In C++, a string is an array of chars ending with a null character. You can declare and initialize a string just as you would any other array. For example:

char Greeting[] = { 'H', 'e', 'l', 'l', 'o', ' ',
'W','o','r','l','d', '\0' };

The last character, '\0', is the null character, which many C++ functions recognize as the terminator for a string. Although this character-by-character approach works, it is difficult to type and admits too many opportunities for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required