1

Well in java with a string you can do this:

int stuff;
string otherstuff;

otherstuff = "I like this much stuff: " + stuff;

But in C++ I have no idea how to.

1
  • 3
    std::to_string. Check out related questions. Commented Nov 19, 2013 at 17:15

3 Answers 3

11

In C++11:

otherstuff = "I like this much stuff: " + std::to_string(stuff);

Historically (and still sometimes useful in C++11):

std::ostringstream ss;
ss << "I like this much stuff: " << stuff;
otherstuff = ss.str();
Sign up to request clarification or add additional context in comments.

2 Comments

Could you help me with this now? When do this: Paint::time = std::to_string(x) + "." + std::to_string(x) + " Hours"; I get numbers like: 12513.13513.4362784.1351253.1235123 hours etc.
@MackenzieGoodwin: If you could write a small example program to demonstrate the problem, and post it in a new question, I'm sure someone could help.
2

I like using stringstream for things like this.

std::stringstream ss;
double dub = 3.14159254;
ss << dub;
std::string s = ss.str();

Comments

1

Also worth noting boost::lexical_cast<std::string>(stuff). If for some reason you can't use C++11

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.