Re: converting string into integer



"Andy" <andy660@xxxxxxxxx> writes:
int a = atoi(argNum);

But I got errot message :error: cannot convert `std::string' to `const
char*' for argument `1' to `int atoi(const char*)'

You can use argNum.c_str() to solve this problem.
I think you are a newer to C++. This is a very basic problem. You can
find the answer in many books very easily.

The original question was posted by "priyanka" <priyankabhar@xxxxxxxxx>.
Please don't snip attribution lines.

If your answer involves C++, please don't post it here. comp.lang.c++
is down the hall, third door on the left, just past the water cooler.
We discuss C here, and we can't check the accuracy of any C++
information.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: text reading
    ... int values_read; ... Read the documentation for sscanf. ... Fix any errors you see. ... Keith Thompson kst-u@xxxxxxx ...
    (comp.lang.c)
  • Re: Casting an array to integer type
    ... > Keith Thompson wrote: ... but it's possible that plain char is signed ... >>The only allowed types for bit-fields are plain int, unsigned int, ... when used as a bit-field base, the lone bit of `s.flag' will ...
    (comp.lang.c)
  • Re: [OT] Puzzle!
    ... Keith Thompson wrote: ... || As far as getchar() returning an int. ... | returns an int. ... | this is a learning forum, and errors matter very much. ...
    (comp.lang.c)
  • Re: First Program
    ... add.c:23: warning: ISO C90 forbids mixed declarations and code ... int size; ... Keith Thompson kst-u@xxxxxxx ...
    (comp.lang.c)
  • Re: How to eliminate this global variable, silent?
    ... Keith Thompson wrote: ... names refer to a variety of things (amonng them) objects." ... A prior message in this thread suggests given 'int a;' a is an object and a variable and ais neither. ...
    (comp.lang.c)