| metulburr (278) | |||
|
My overall goal in this was to convert binary strings to integers, but now i am interested in also learning stringstream. After looking around i found the method stringstream to be best? The only problem i found when i was trying to use it to convert binary strings to ints was it stripped the initial 0, if it had one. Now this makes sense on average use, but what if you were using it to convert binary strings to ints?
| |||
|
Last edited on
|
|||
| maeriden (341) | |
|
What about strtol()? http://www.cplusplus.com/reference/cstdlib/strtol/ | |
|
|
|
| metulburr (278) | |
|
to be honest i was looking for a standard way for (int into str and str to int. ) I was looking at not to confuse myself as i just returned to c++ from python. I'm surprised at how hard it is to do basic things that in python i didnt even think of. so in essence, i was looking for the same method to convert to and from, whereas atoi or itoa, ummm one of them is not in the standard library of C++. | |
|
|
|
| Chervil (1206) | |||||||||
That's simply a matter of how the output is formatted. By choosing the width and fill character, the number can be displayed as you wish:
Output:
Well, the above is an output issue. The input is not affected, hence it will work correctly. As already suggested, strtol() is a standard way to convert a string to an integer, using any base from 2 to 36.For amusement purposes, one of many, many ways to convert an int to a binary string:
| |||||||||
|
Last edited on
|
|||||||||