#include#include int main() { std::string str1 = "hello"; std::string str2 = "world"; std::string str3 = str1 + " " + str2; std::cout << str3 << std::endl; return 0; }
#include#include int main() { std::string str = "hello world"; std::size_t pos = str.find("world"); if (pos != std::string::npos) { std::cout << "Substring found at position " << pos << std::endl; } else { std::cout << "Substring not found" << std::endl; } return 0; }
#includeHere, we have used the length() function to determine the length of a string (str). The common String library is part of the C++ Standard Library (STL).#include int main() { std::string str = "hello"; std::cout << "Length of string: " << str.length() << std::endl; return 0; }