//sLine is the string
for(int l = 0; l < sLine.length(); l++)
{
string sNumber;
if(sLine[l] == '-')
{
sNumber.push_back(sLine[l]);
sNumber.push_back(sLine[l + 1]);
l++;
}
else if(sLine[l] != '\t')
{
sNumber.push_back(sLine[l]);
}
const char* testing = sNumber.c_str();
int num = atoi(testing);
cout << num;
}
I have this for-loop which checks each character of the string and converts every number in this string to be a int. But for some reason, the atoi function is doing it twice so when I cout it, it displays it twice for some reason... Why is that?
example:
INPUT
3 3 -3 9 5
-8 -2 9 7 1
-7 8 4 4 -8
-9 -9 -1 -4 -8
OUTPUT
3030-309050
-80-20907010
-70804040-80
-90-90-10-40-80