C++ iostream: Using cin >> var and getline(cin, var) input errors

前端 未结 5 1048
旧时难觅i
旧时难觅i 2020-12-06 23:11

I\'m creating a simple console application in C++ that gets string and char inputs from the user. To make things simple, I would like to use the string and

5条回答
  •  余生分开走
    2020-12-06 23:18

    You are using std::isstream::ignore() before std::getline(). std::cin.ignore() will extract the first character from the input sequence and discard that.

    http://www.cplusplus.com/reference/istream/istream/ignore/

提交回复
热议问题