![]() |
|
#1
|
|||
|
|||
Is there a better way of converting Int to std::stringI'm curious if theres a better way of converting int data types into std::string. What I have works but i'm almost sure there's a better way of doing it. Let me know if you guys know of anything easier or any suggestions u have. Cause my way is somewhat limited.
I've tried this code and it works but its still kinda inefficiant I think its the only thing i could think of. CPP / C++ / C Code:
__________________
There are 10 kinds of people in this world. Those who speak binary and those who dont. |
|
#2
|
||||
|
||||
Re: Is there a better way of converting Int to std::stringIf you will include the string header (on some compilers there may not be the need) you can just assign the char array to the std::string, since there is an assignment operator defined for this:
CPP / C++ / C Code:
But if you don't want to use this C hack and do it the "C++ way", you can include sstream and use the stringstreams for conversion: CPP / C++ / C Code:
You can use stringstreams just like you use cin and cout. This method is actually a C++ mirror for the C sprintf method for conversion. Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
||||
|
||||
Re: Is there a better way of converting Int to std::stringHi monalin,
You can find more information about this in the following links: Converting Int to a string 1 Converting int to string 2 Converting int to string 3 Converting int to string 4 Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Issues converting Fahrenheit to celsius | Skampy | C++ Forum | 7 | 25-Feb-2006 09:04 |
| Converting a constant to a string | Darth Predator | C++ Forum | 2 | 26-Sep-2005 18:11 |
| Converting string to float | CT++ | C++ Forum | 2 | 10-May-2005 12:29 |
| I am reviewing Arrays and need help converting some strings to arrays | jenmaz | C Programming Language | 22 | 23-Nov-2004 00:26 |
| converting binary to integer... | tru504187211 | C++ Forum | 3 | 10-Feb-2004 08:11 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The