Convert int to string

A

Azathot

Leszek said:
How to I can convert int variable to string?

--- CUT HERE ---

#include <iostream>
#include <string>
#include <sstream>

template< class T >
std::string to_string( const T& _t ) {

std::stringstream os;

os << _t;

return os.str( );

};

int main( ) {

std::cout << to_string( 10 ) << std::endl;

return 0;

}

--- CUT HERE ---

Bye!
 
L

Leszek Klich

Hello!

I'm beginer programmer in QT (Linux and Windows). I have a problem. How to I
can convert int variable to string? I searching function or tips but I can't
found.
Please help me.

Leszek
 
J

Jacques Labuschagne

Leszek said:
Hello!

I'm beginer programmer in QT (Linux and Windows). I have a problem. How to I
can convert int variable to string? I searching function or tips but I can't
found.
Please help me.

Leszek

#include <string>
#include <sstream>

template<typename T>
std::string to_string(const T& t){
std::stringstream s;
s << t;
return s.str();
}

Jacques.
 
T

Tanguy Fautré

Leszek Klich said:
Hello!

I'm beginer programmer in QT (Linux and Windows). I have a problem. How to I
can convert int variable to string? I searching function or tips but I can't
found.
Please help me.

Leszek


template <class T>
inline std::string ConvertToString(const T & Value)
{
std::eek:stringstream Out;
Out << Value;
return Out.str();
}


Tanguy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top