Here is the excerpt from what I read:
The second new idea is that we can use + to concatenate a string and a string literal--or, for that matter, two strings (but not two string literals).
[/quote]
The second new idea is that we can use + to concatenate a string and a string literal--or, for that matter, two strings (but not two string literals).
[/quote]
std::string String = "String literal";
the variable called "String" (of type std::string) is a string, the actual text inside quotes is a string literal.std::string a = "a";
std::string b = "b";
std::string c = a+b;//concatenate two strings
c = a+"literal";//concatenate 1 string and 1 literal
c = "foo" + "bar";//concatenate 2 literals -- this doesn't work, it hopefully will give you a compile error.
c = std::string("foo") + "bar";//turning one of them into a temporary string does make it work
int myInt = 357; //357 = a number literal.
int myInt = #00FFAA; //#00FFAA = a number literal, but in hexadecimal format.
std::string myString = "Hello!"; //"Hello!" = a string literal.
float myFloat = 357.0f; //A float literal. The 'f' means 'float'.
double myDouble = 357.0; //A double literal. Any decimal number is a double by default, I think.
double myDouble = 357.0f; //A float literal (notice the 'f'). It'll get converted to a double during the assignment.
int myInt = myOtherInt;
int myInt = 357; //357 = Sort-of like an unnamed variable.
357 = some 'int'-like type.
true = a bool
false = a bool
357.0 = a double
357.0f = a float
char myChar = 'A'; //Single quotes on their own equals 'char' literal.
"my string"
char *myCString = "String literal";
std::string myString = myCString;
std::string myString ="String literal";
char *myCString = "String literal A" + "String literal B"; //Won't work!
char *myCStringA = "text";
char *myCStringB = "text";
char *myCStringC = myCStringA + myCStringB; //Won't work!
std::string strA = "A";
std::string strB = "B";
std::string myStr = strA + strB + "string literal";
myStr += "more text";
Weight myWeight = 110_lbs; //Where 'Weight' is a custom made type, and '_lbs' is a user-defined literal.