appending string in c 2b 2b

Solutions on MaxInterview for appending string in c 2b 2b by the best coders in the world

showing results for - "appending string in c 2b 2b"
Nicola
03 Feb 2017
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}