converting string to int in C++
- by xbonez
I am trying to convert a string I read in from a file to an int value so I can store it in an integer variable. This is what my code looks like:
ifstream sin;
sin.open("movie_output.txt");
string line;
getline(sin,line);
myMovie.setYear(atoi(line));
Over here, setYear is a mutator in the Movie class (myMovie is an object of Movie class) that looks like this:
void Movie::setYear(unsigned int year)
{
year_ = year;
}
When I run the code, I get the following error:
error C2664: 'atoi' : cannot convert parameter 1 from 'std::string' to 'const char *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called