Sign in to follow this  
derek7

How to connect string and in?

Recommended Posts

Frequency    442
You can use stringstreams to resolve this:


#include <sstream>
using std::stringstream;

stringstream converter;
converter << "light" << ext;
string s = converter.str();

Share this post


Link to post
Share on other sites
Scet    960
You have to cast it to a string. Either use boost::lexical_cast or roll your own function.


#include <sstream>

template<typename R, typename T>
R lexical_cast(T const& value) {
R ret;
std::stringstream ss;
ss << value;
ss >> ret;
return ret;}

int ext = 0;
string str = "light";

string s = str + lexical_cast<string,int>(ext++);





It may seem like a lot, but it's a very usefull function to have around.

Edit: beaten :(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this