How to use cin with unknown input types?

前端 未结 2 1687
清歌不尽
清歌不尽 2021-01-22 22:20

I have a C++ program which needs to take user input. The user input will either be two ints (for example: 1 3) or it will be a char (for example: s).

I know I can get th

2条回答
  •  旧时难觅i
    2021-01-22 22:43

    Use std::getline to read the input into a string, then use std::istringstream to parse the values out.

提交回复
热议问题