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>
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
1#include<iostream>
2#include <string>
3int main() {
4 //"Ever thing inside these double quotes becomes const char array"
5// std::string namee = "Caleb" +"Hello";//This will give error because adding const char array to const char array
6 std::string namee = "Caleb";
7 namee += " Hello";//This will work because adding a ptr to a actual string
8 std::cout << namee << std::endl;// output=>Caleb Hello
9//You can also use the below
10 std::string namee2 = std::string("Caleb")+" Hello";// This will work because constructor will convert const char array to string, adding a ptr to string
11 std::cout << namee2 << std::endl;// output=>Caleb Hello
12 std::cin.get();
13}