定义:
直观一点就是把输入流里的内容看做是一个字符串的列队 里面存放的都是一个一个的字符 而这里的putback函数就相当于列队里的push函数。
表现形式
下面这段代码能帮助您更清晰的理解get 和 putback函数 :
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cctype> #include <algorithm> using namespace std; int main() { char c; int n; char str[256]; cout << "Enter a number or a word: "; c = cin.get(); if ( (c >= '0') && (c <= '9') ) { cout << c << " --- the middle output" << endl; cin.putback (c); cin>> n; cout<< "You have entered number " << n << endl; } else { cout << c << " --- the middle output" << endl; cin.putback (c); cin>> str; cout<< " You have entered word " << str << endl; } return 0; }
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/25170.html