in Education by
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
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() );

Related questions

0 votes
    I am a beginner and I just need a bit of help on why I getline is showing an error: this is what I have so far ... payments[MAX_ITEMS]; ifstream iFile; if ( argc != 2 ) { cout...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am a beginner and I just need a bit of help on why I getline is showing an error: this is what I have so far ... payments[MAX_ITEMS]; ifstream iFile; if ( argc != 2 ) { cout...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Which of the following is used to terminate the function declaration in C++? a) ; b) ] c) ) d) :...
asked Oct 19, 2022 in Education by JackTerrance
0 votes
    What will be the output of the following C++ function? int main() { register int i = 1; int *ptr = &i; cout << *ptr ... may be possible b) Compiler error may be possible c) 1 d) 0...
asked Oct 19, 2022 in Education by JackTerrance
0 votes
    // merge.cpp // merges two containers into a third #include #include //for merge() using namespace std; int src1[] = { 2, 3, 4, ... , src1+5, src2, src2+3, dest); for(int j=0; j...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have a function value(x) which is overloaded for many types such that: double value(double x) { return x; } double ... [-Wreturn-local-addr] in the following code: Matrix33 m; m...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 18, 2022 in Education by JackTerrance
0 votes
    Is there a function in the C Library under Linux which can set the length of a file? Under ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Now i am writing a MFC program with opengl in it. And when i tried to combine opengl with MFC, i ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Now i am writing a MFC program with opengl in it. And when i tried to combine opengl with MFC, i ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    The Function Key F5 is used in a webpage to___________the page (a) Exit (b) Create another window (c) Reload (d) Add a new tab Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Derive a Canonical POS expression for a Boolean function F, represented by the following truth table : 1 A B C F 0 0 0 ... 1 0 1 1 1 1 Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
...