A string is a sequence of characters.
Strings are typically enclosed in double quotes (unlike chars, which are individual letters of the alphabet enclosed usually in single quotes).
Declaring strings:
string varname = "your string here";
char varname[] = "string"
char varname[] = {'E','S','3,'0','1'}
char* varname = "DSA-2";
In all cases, you can print the string using cout
as usual.
Note that char*
is a pointer to a constant string literal, and it is more appropriate to use the following: const char* varname = "DSA-2";
as opposed to what is written above. This particular type of declaration gives us immutable strings.