Help it quick.

I have a variable of type int say telephone
and having value 2340 in it,now i want to stor this in string what should i do?
i can't use index with telephone,and want to store all four char(2340) in string.
closed account (o1vk4iN6)
You can you istringstream to do what you want, there is also a itoa() which may not be in all lbraries.

Boost:: lexical_cast
Modern C++

1
2
int value = 2340;
string str = std::to_string(value);


Old C++ with boost

1
2
int value = 2340;
string str = boost::lexical_cast<std::string>(value);


Old C++ without boost

1
2
3
4
int value = 2340;
std::ostringstream buf;
buf << value;
std::string str = buf.str();



Topic archived. No new replies allowed.