Until now, text has mostly appeared directly inside output statements. A std::string is a value that stores a sequence of characters, so you can name text, change it, pass it to functions, and build new text from it.
Include <string> to use this type. Double quotes mark a text literal, while single quotes mark one char.
#include <iostream>
#include <string>
int main() {
std::string place = "Riverside";
std::string notice = place + " market";
std::cout << notice << '\n';
return 0;
}
The + operator joins strings here instead of adding numbers. The space at the start of " market" is part of that literal. C++ does not insert spaces automatically, so omitting it would join the words directly.
Start a joining expression with a std::string value, as the example does. Two bare quoted literals do not support this same + operation by themselves. You can join a string variable with another string or a literal, then join more pieces to that result.
The starter already stores the first and last names, but displayName contains "": empty text. Replace that initializer with an expression using both name variables. Put the separating space inside quotes as its own piece of text. Without it, the join would run the two names together; printing the result does not add a separator for you.
These lessons use plain English letters, digits, and punctuation. Later character-position operations will refer to these simple one-byte characters, not attempt to handle every writing system.
displayName by joining firstName, one space, and lastName. Expect Member: Mina Patel.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.