-
Error C2664
I am trying to convert the strings into inegers in this code:
Code:
string line;
string oct1;
string oct2;
string oct3;
string oct4;
int i = 0;
while ( ! in.eof())
{
while(getline(in,line))
{
while(line[i] != '.')
{
oct1 = oct1 + line[i];
i++;
}
cout<<oct1<<" ";
i++;
while(line[i] != '.')
{
oct2 = oct2 + line[i];
i++;
}
cout<<oct2<<" ";
i++;
while(line[i] != '.')
{
oct3 = oct3 + line[i];
i++;
}
cout<<oct3<<" ";
i++;
while(i != line.length())
{
oct4 = oct4 + line[i];
i++;
}
cout<<oct4<<endl;
}
}
oct 1, 2, 3, and 4 I am trying to convert to an integer
When I use the atoi or the sscanf commands this error comes up
-
atoi takes a c character array rather than a std::string object. Fortunately, we can get a character array from a std::string with the c_str() method.
So instead of:
Code:
i = atoi(oct4); /* This will cause an error. */
we use
Code:
i = atoi(oct4.c_str()); /* This will work. */
You may be interested in the inet_addr function.
For future reference:
- Please post the actual error text.
- Please post the line that is causing the error.
- Please post C questions in the C forum and C++ questions in the C++ forum.