
-----------------------------------
hamid14
Sun Nov 21, 2010 1:24 pm

convet int to string?
-----------------------------------
I want to convert day which is an int type, to displayDays, which is a string type variable. im using dev-c++, any help is appreciated.

-----------------------------------
TheGuardian001
Sun Nov 21, 2010 2:52 pm

Re: convet int to string?
-----------------------------------
the itoa()method will convert a int to a string (or rather, a char array). Likewise, atoi will convert a string to an int.

-----------------------------------
OneOffDriveByPoster
Sun Nov 21, 2010 4:50 pm

Re: convet int to string?
-----------------------------------
itoa is not portable. You can use sprintf or an ostringstream,

-----------------------------------
hamid14
Sun Nov 21, 2010 5:10 pm

Re: convet int to string?
-----------------------------------
Any examples? I cant seem to find any good ones online >.>

-----------------------------------
OneOffDriveByPoster
Mon Nov 22, 2010 8:12 pm

Re: convet int to string?
-----------------------------------
Any examples? I cant seem to find any good ones online >.>A useful skill in programming is to be able to build solutions from documentation of APIs and the such. For example, the declaration for std::ostringstream can be added into your program by including . std::ostringstream is a typedef for a specialization of std::basic_ostringstream (which has a member function called str()). So you can create an ostringstream object, use an inserter on it with the number to output and then get a string back with the output.
