concat, substring strings
Consider the following example for various operations on strings
#include <string> #include <iostream> using namespace std; int main() { string s1("this string represents s1"); string s2("All mangoes are bananas"); string s3("snow is the purest form of water"); // Copy the first 8 chars from s1 in string s4 // string s4(<string>, <starting index>, <end index>); string s4(s1, 0, 8); //appending strings string s5 = string (s1, 0, 4) + " helllo " + string (s3, 0, 8); // finding substring //s3.substr(<from starting index>, <upto index>) string s6 = s3.substr(5, 10); string s7 = s3.substr(1, 5) + s5; cout << s1 << endl; cout << s2 << endl; cout << s3 << endl; cout << s4 << endl; cout << s5 << endl; cout << s6 << endl; cout << s7 << endl; getchar(); return 0; }