Dec 25, 2012 at 5:48pm Dec 25, 2012 at 5:48pm UTC
Hi.
I used atoi(string1.c_str()) for convertig a binary string to integer.
but it always return 0.
why?????!!!!1
Dec 25, 2012 at 6:04pm Dec 25, 2012 at 6:04pm UTC
What do you mean when saying "binary string"? atoi can only convert to int a representattion of an integer number writtten in decimal notation.
Last edited on Dec 25, 2012 at 6:04pm Dec 25, 2012 at 6:04pm UTC
Dec 25, 2012 at 6:17pm Dec 25, 2012 at 6:17pm UTC
I mean that in this string we just have 0,1.
Dec 25, 2012 at 6:45pm Dec 25, 2012 at 6:45pm UTC
Yes, but what does the string contain?
Dec 25, 2012 at 6:45pm Dec 25, 2012 at 6:45pm UTC
If 'number' does not represent an integer literal then of course you will not get a valid value.
Dec 25, 2012 at 6:48pm Dec 25, 2012 at 6:48pm UTC
it contains 1 and 0.
edit:
it can get a number between and including 0 and 9
Last edited on Dec 25, 2012 at 7:03pm Dec 25, 2012 at 7:03pm UTC
Dec 25, 2012 at 9:29pm Dec 25, 2012 at 9:29pm UTC
May I ask, 1 and 0 like this, "1 0" or " 0 1 " or "10" or what?
what is "it", please?
At any rate,
atoi()
should be able to handle any string which converts to a valid integer, usually in the range "-2147483648" to "+2147483647". The string "10" certainly fits within that range.
As stated in the reference below, if the input is not a valid integer, the result is zero.
http://www.cplusplus.com/reference/cstdlib/atoi/
Last edited on Dec 25, 2012 at 9:30pm Dec 25, 2012 at 9:30pm UTC
Dec 26, 2012 at 7:08am Dec 26, 2012 at 7:08am UTC
my problem is similar, I have to convert a string to int and strings.
For example, 123TCat and Dog W346 edf fedh are good
assign 123 to x
Cat and dog to str
346 to y
are good to line
Dec 26, 2012 at 5:55pm Dec 26, 2012 at 5:55pm UTC
Well, that was hard work. I asked three times what was the exact string, and still got no answer. We would have reached the solution much faster if we worked together in cooperation.
Dec 26, 2012 at 6:08pm Dec 26, 2012 at 6:08pm UTC
ok,I'm sorry!!
Thank you again
Last edited on Dec 26, 2012 at 6:12pm Dec 26, 2012 at 6:12pm UTC