I'm trying to convert a string to long. It sounds easy, but I still get the same error. I tried:
include <iostream>
include <string>
using namespace std;
int main()
{
string myString = "";
cin >> myString;
long myLong = atol(myString);
}
But always the error:
.../main.cpp:12: error: cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'long int atol(const char*)'
occured. The reference says following:
long int atol ( const char * str );
Any help?