#include <sstream>
//declare it somewhere
std::stringstream ss; //internal string empty at beginning
//usage
ss << "You, along with your " << numFriends << " friends, set up camp..."; //append this to the internal string
std::string setUpCampLabel = ss.str(); //get a copy of stringbuilder internal string
ss.clear(); //clear the internal string
ss << "You were eaten by a bear!";
std::cout << setUpCampLabel << std::endl <<ss.str(); //it is possible to print the internal string directly
How is this any more efficient than just putting:
cout << "You, along with your " << numFriends << " friends, set up camp..." << endl << "You were eaten by a bear!"
First, efficiency wasn't your question. How to put variables into a [font=courier new,courier,monospace]string[/font] was, and that's what was shown. Yes, doing that is "less efficient" than just printing everything out to [font=courier new,courier,monospace]cout[/font] directly.
I'm also using DevC++, not Visual Studio.
Why you shouldn’t use Dev-C++ (or maybe you're using an updated version of Dev-C++?)
So, in short, you simply can't declare a string and put an integer variable within it? You have to do that?
Nope. Welcome to C++ . You either have to use [font=courier new,courier,monospace]stringstream[/font], [font=courier new,courier,monospace]to_string()[/font] (as Zaoshi Kaba showed), [font=courier new,courier,monospace]itoa()[/font] (please, please, please don't use this), your own custom method, an external library like [font=courier new,courier,monospace]boost[/font] and its [font=courier new,courier,monospace]lexical_cast[/font], etc.
@superman3275: Did I miss something? I thought he was trying to put [font=courier new,courier,monospace]int[/font]s into [font=courier new,courier,monospace]string[/font]s, not [font=courier new,courier,monospace]string[/font]s into [font=courier new,courier,monospace]int[/font]s...