輸入小數點後是否有任何方法去除尾部空白? 例如:僅通過istream函數從輸入流中刪除空格
10 A
我想捕捉空白結束後的第一個字符。 (這得是的\ n是真的如果不是,那麼假
我試圖至今:?
cout << "Please enter a number: ";
cin >> n;
if (cin.peek() == ' ')
//Something to catch the whitespaces
if(cin.fail() || cin.peek() != '\n')
cout << "Not a number." << endl;
else
cout << "A number." << endl;
能夠做到這一點功能的IStream
(我知道cin.fail可以做好事,但它仍然不會考慮輸入10A作爲失敗)
只是讓整條生產線,你應該找到生成的字符串要好得多檢索信息。 – chris 2013-03-28 04:17:29
http://stackoverflow.com/questions/710604/how-do-i-set-eof-on-an-istream-without-reading-formatted-input – 2016-04-12 06:05:40