+ 3

How to convert a float/int... to a string in C++?

Hi guys, I am using std::string class and I don't know how to convert a float/int to a string or how to concateniate them in one string , I need your help please 😊 BTW , I am using code::blocks 16.01

19th Aug 2017, 1:45 PM
ayoub soussi
ayoub soussi - avatar
4 Answers
+ 3
sprintf : I read something about it but I don't know if it'll work in C++ . the to_string method doesn't work with my IDE😕 Anyway , thank you , I already fixed the problem
20th Aug 2017, 1:15 AM
ayoub soussi
ayoub soussi - avatar
+ 2
sorry I found the solution 😃 for those who don't know how , we will use this function ( nb2string ): #include< sstream> using namespace std ; template <class T> string nb2String(T nb) { ostringstream s; s << nb; return s.str(); }
19th Aug 2017, 2:05 PM
ayoub soussi
ayoub soussi - avatar