putback.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 29 行
CPP
29 行
#include <iostream.h>
void main( void ) {
char stk[20], ech;
int i = 0, size = 4; //default putback size
cout << "Enter a string: " << endl;
do {
ech = cin.get();
cout << ech;
stk[i++] = ech; // store the extracted character
} while( ech != '\n' );
// put back the characters into the istream object
for( int k = i; k > (i-size-1); --k ) {
cin.putback( stk[k] );
}
cout << "The last " << size
<< " characters has been put back into the istream object."
<< endl;
// reprint the string
cout << "The characters stored in the object: " << endl;
for( int j = 0; j < size; j++ ) {
ech = cin.get();
cout << ech;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?