int main()
{
ifstream diagram;
diagram.open("diagram.in");
string line;
int one;
int two;
getline(diagram, line);
one = atoi(line);
getline(diagram, line);
two = atoi(line);
system("PAUSE");
return 0;
}
</code>
The error i get is the following: error C2664: 'atoi' : cannot convert parameter 1 from 'std::string' to 'const char *'
- Neil.
January 26th, 2010, 04:19 PM
Lindley
Re: Getline_input_to_int
Yes, atoi() is a C function, so it doesn't know about std::string. The error is telling you exactly what's wrong. You'll need to use std::string's compatibility method, c_str().
January 26th, 2010, 04:27 PM
Philip Nicoletti
Re: Getline_input_to_int
Are there other chars on each line besides what you have shown ?
if not, whu not read directly into an int variable ?
January 26th, 2010, 04:29 PM
Neil.Dyke
Re: Getline_input_to_int
Thank you, Lindley. That helped!
@ Philip, is there a way i can read it directly into int?