0

I want to convert my command-line char* argv[] argument to int. I am studying to OpenCV and there it used like this:

int main(int argc, char* argv[])
{
    int divideWith = 0;
    stringstream s;
    s << argv[2];
    s >> divideWith; //This is my argument converted to int
}

It used a stringstream class. Is there any other way to convert strings (char arrays) to int. I already know to do this:

char a = '7';
int b = a;

In here it asigns the ASCII representation to my int variable. I want it to be like this:

char a = '7';
int b = somefunction(a); //A function, algorith or what ever that returns an int '7'
cout << b;

This should give me the 7 result in comand-line.

Bora Semiz
  • 223
  • 2
  • 14
  • also possible duplicate of http://stackoverflow.com/questions/7663709/convert-string-to-int-c – Messa Feb 08 '15 at 21:02
  • Many options available: std::atoi, std::stoi, std::stringstream, etc. But before that, maybe read a complete C++ book – SwiftMango Feb 08 '15 at 22:00

0 Answers0