c++ converting string to int

前端 未结 4 612
我在风中等你
我在风中等你 2021-01-28 06:55
//sLine is the string
for(int l = 0; l < sLine.length(); l++)
{
    string sNumber;
    if(sLine[l] == \'-\')
    {   
        sNumber.push_back(sLine[l]);
        sN         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 07:20

    You output extra 0 for the characters which are not digits. The problem is that atoi returns 0 when it cannot convert the input, so your whitespaces are printed as zeroes.

提交回复
热议问题