c++ converting string to int

前端 未结 4 653
我在风中等你
我在风中等你 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:29

    That seems like a painful way to recreate the wheel. You'd be better off using a stringstream to parse this.

    std::stringstream strm(sLine);
    int num;
    while(strm >> num)
    {
        std::cout << num << std::endl;
    }
    

提交回复
热议问题