Convert std::string to integer

Daniel Del Core picture Daniel Del Core · Sep 27, 2012 · Viewed 31.8k times · Source

I'm trying to convert a std::string stored in a std::vector to an integer and pass it to a function as a parameter.

This is a simplified version of my code:

vector <string> record;
functiontest(atoi(record[i].c_str));

My error is as follows:

error: argument of type ‘const char* (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::)()const’ does not match ‘const char*’

How can I do this?

Answer

Pete Becker picture Pete Becker · Sep 27, 2012

With C++11:

int value = std::stoi(record[i]);