Stringstream extract integer

后端 未结 4 532
小鲜肉
小鲜肉 2021-01-04 18:27

Why do I fail to extract an integer value into the Num variable?

#include 
#include 
#include 

usi         


        
4条回答
  •  余生分开走
    2021-01-04 18:58

    Why are you reading into a temp string variable?

    You can just read from the stringstream into an int...

    int main()
    {
        string Digits("1 2 3");
        stringstream ss(Digits);
        int Temp;
        vector Tokens;
    
        while(ss >> Temp)
            Tokens.push_back(Temp);
    }
    

提交回复
热议问题