-
Notifications
You must be signed in to change notification settings - Fork 0
String
Sgt. Mahdi edited this page Apr 10, 2025
·
6 revisions
String is an Array of characters.
Important
at the end of array you must add '\0' which represents the end of string.
char string[] = { 'H', 'e' ,'l', 'l', 'o', '\0'};
std::cout << string << std::endl; //Hello
if you forget to add '\0' at the end, you'll end up having strange characters in your string
char string[] = { 'H', 'e' ,'l', 'l', 'o'};
std::cout << string << std::endl; //Hello╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
There are different ways to make a string in C++
const char* string = "Hello World!"; //'\0' will be added automatically by the IDE
std::string string = "Hello World!"; //'\0' will be added automatically by the IDE
char arrayOfCharacters[] = "Hello World!"; //'\0' will be added automatically by the IDE
ASCII stands for (American Standard Code for Information Interchange), is set of numeric codes that computers use to represent English characters and some special symbols.
char string[] = { char(72), char(101), char(108), char(108), char(111),'\0'};
std::cout << string << std::endl; //Hello
In this website, DEC (Decimal number) stands for ASCII code of each character. See ASCII Codes
Tip
One of the usages of the ASCII code is to convert lowercase characters into uppercase
You can see the example in My Custom String Class