1#include <iostream>
2#include <cstdlib>
3
4std::string text = "hello";
5std::string moretext = "there";
6std::string together = text + moretext;
7std::cout << together << std::endl;
8
9>> hello there
1#include <iostream>
2using namespace std;
3
4int main()
5{
6 string s1, s2, result;
7
8 cout << "Enter string s1: ";
9 getline (cin, s1);
10
11 cout << "Enter string s2: ";
12 getline (cin, s2);
13
14 result = s1 + s2;
15
16 cout << "Resultant String = "<< result;
17
18 return 0;
19}
20
1#include <iostream>
2#include <sstream>
3
4int main() {
5 std::string value = "Hello, " + "world!";
6 std::cout << value << std::endl;
7
8 //Or you can use ostringstream and use integers too
9 //For example:
10
11 std::ostringstream ss;
12 ss << "This is an integer" << 104;
13 std::cout << ss.str() << std::endl;
14}
1string first_name = "foo"
2string last_name = "bar"
3std::cout << first_name + " " + last_name << std::endl;
1int x=5;
2int y= 10;
3
4int z = x+y;//z==15
5
6string s1="Abhi";
7string s2="gautam";
8
9string s3= s1+s3;//s3==Abhigautam
10