C++ examples for STL:string
Create string object is various ways
#include <iostream> #include <string> using namespace std; int main()//from w w w.j a va 2s. com { string str1; // an empty string string str2("this is a test"); string str3 = "test test test"; string str4(str3); string str5(str4, 4); string str6 = "linear"; string str7(str6, 3, 3); cout << "str1 is: " << str1 << endl; cout << "str2 is: " << str2 << endl; cout << "str3 is: " << str3 << endl; cout << "str4 is: " << str4 << endl; cout << "str5 is: " << str5 << endl; cout << "str6 is: " << str6 << endl; cout << "str7 is: " << str7 << endl; return 0; }