#include#include int main() { std::string str = "Hello, World!"; std::cout << str << std::endl; return 0; }
#include#include int main() { std::string str1 = "Hello"; std::string str2 = " World!"; std::string str3 = str1 + str2; std::cout << str3 << std::endl; return 0; }
#includeIn this example, we create a std::string object called "str" and initialize it with the value "Hello, World!". We then use the string member function "length()" to get the length of the string, which is stored in a variable "len". Finally, we output the length of the string to the console. Package library: Standard C++ library#include int main() { std::string str = "Hello, World!"; std::string::size_type len = str.length(); std::cout << "Length of string is " << len << std::endl; return 0; }