Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 convet int to string?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hamid14




PostPosted: Sun Nov 21, 2010 1:24 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Sun Nov 21, 2010 2:52 pm   Post subject: 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




PostPosted: Sun Nov 21, 2010 4:50 pm   Post subject: Re: convet int to string?

itoa is not portable. You can use sprintf or an ostringstream,
hamid14




PostPosted: Sun Nov 21, 2010 5:10 pm   Post subject: Re: convet int to string?

Any examples? I cant seem to find any good ones online >.>
OneOffDriveByPoster




PostPosted: Mon Nov 22, 2010 8:12 pm   Post subject: Re: convet int to string?

hamid14 @ Sun Nov 21, 2010 5:10 pm wrote:
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 <sstream>. 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.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: