C++一些小技巧

1.获取输入的空白字符的方法。
使用istream的get()成员函数(ostream的put()成员函数一般与get配合使用)
如果你需要来回切换是否忽略空白的话,这种方法才是首选

int count = 0;
char c;
while (cin.get(c)) {  // Always reads whitespace chars.
        count++;
        cerr << count << endl;
}


使用noskipws操作符。

只能忽略空白

int count = 0;
char c;
cin >> noskipws;    // Stops all further whitespace skipping
while (cin >> c) {  // Reads whitespace chars now.
       count++;
       cerr << count << endl;






posted @ 2018-07-17 21:34  LyndonMario  阅读(241)  评论(0编辑  收藏  举报