I want to create a string containing many variables:
std::string name1 = "Frank"; std::string name2 = "Joe"; std::string name3 = "Nancy"; std::string name4 = "Sherlock"; std::string sentence; sentence = name1 + " and " + name2 + " sat down with " + name3; sentence += " to play cards, while " + name4 + " played the violin.";
This should trigger a sentence that reads
Frank and Joe sat down with Nancy to play cards, and Sherlock played the violin.
My question is: what is the best way to achieve this? I am concerned that continued use of the + operator is inefficient. Is there a better way?
source share