Strings

Strings are objects that represent sequences of characters. In C++, there are two ways to create strings: string class or using C-style character strings.

String Class

The standard string class provides support for strings in C++.

std::string welcome = "Hi";
std::string user_name = "@sonny";
std::string message = "Good nite! πŸ˜‡";

C-Style Character Strings

The C-style character string originated from the C language and continues to be supported within C++.

In C, the string is actually an array of characters, followed by a null character '\0'.

char message[] = "Howdy";

So here’s the memory presentation:

Character | 'H' 'o' 'w' 'd' 'y' '\0'
Index | 0 1 2 3 4 5
Address | 23451 23452 23453 23454 23455 23456
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn C++ on Codecademy

Edit this page on GitHub

Contributors