0 votes
in Education by (1.7m points)
I dont' quite understand how this function works.

I wrote a simple programming reading one line with getline().

for example:

ifstream in;

in.open("example.txt");

string line;

getline(in, line);

cout << line << endl;

When I tried to run this program I received an error message like this.

`assign1_2.cpp:33:20: error: cannot convert 'std::string {aka std::basic_string<char>}'    to 'const char*' for argument '1' to 'int atoi(const char*)'

I simply don't understand what went wrong here. Please help!. I am a newbie to c++.

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
You didn't show the code with the error, but the error says you tried to call atoi with an argument of type std::string. atoi takes a C string (man atoi), so you need to call it like:

atoi( line.c_str() );
...