Data Types
Strings
The std::string type stores and combines text.
Strings
strings.cpp
#include <iostream>
#include <string>
int main() {
std::string firstName = ;
std::string greeting = "Hello, " + firstName + "!";
int length = greeting.size();
std::cout << "greeting=" << greeting << std::endl;
std::cout << "length=" << length << std::endl;
return 0;
}
#include <iostream>
#include <string>
int main() {
std::string firstName = ;
std::string greeting = "Hello, " + firstName + "!";
int length = greeting.size();
std::cout << "greeting=" << greeting << std::endl;
std::cout << "length=" << length << std::endl;
return 0;
}
#include <iostream>
#include <string>
int main() {
std::string firstName = ;
std::string greeting = "Hello, " + firstName + "!";
int length = greeting.size();
std::cout << "greeting=" << greeting << std::endl;
std::cout << "length=" << length << std::endl;
return 0;
}
string concatenation
The `+` operator can join two `std::string` values into a new string.