converting string to int in C++

前端 未结 5 1531
南笙
南笙 2021-01-07 05:07

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         


        
5条回答
  •  一生所求
    2021-01-07 05:40

    Rather than using std::getline(std::string&, std::istream&), why not just use the stream extraction operator on the file?

    ifstream sin;
    sin.open("movie_output.txt");
    unsigned int year = 0;
    sin >> year;
    myMovie.setYear(year);
    

提交回复
热议问题