Best way to get ints from a string with whitespace?

后端 未结 5 935
挽巷
挽巷 2020-12-08 22:30

I know this is simple, I just can\'t recall the best way to do this. I have an input like \" 5 15 \" that defines the x and y of a 2D vector array. I simply ne

5条回答
  •  臣服心动
    2020-12-08 22:56

    Here's the stringstream way:

    int row, col;
    istringstream sstr(" 5 15 ");
    if (sstr >> row >> col)
       // use your valid input
    

提交回复
热议问题