Subj : Re: question on cin.putback() .. To : borland.public.cpp.borlandcpp From : maeder Date : Sun Jan 02 2005 05:22 pm "Stan" writes: > #include Side note: The ISO C++ Standard asks you to also #include and for your program to have defined behavior. > using namespace std; > > int main() > { > cout << "input 'abcdef' :"; > char c = cin.peek(); > cin.putback('0'); > char chararray[10]; > cin >> chararray; > cout << chararray; > } These are 5 I/O operations, each of which can fail. You should check for sucess of these operations before taking conclusions from entities (apparently) read in. if (std::cout << "input 'abcdef' :") { std::istream::int_type const i(cin.peek()); if (i==std::istream::traits_type::eof()) // peek failed else if (std::cin.putback('0')) { // etc. } else // putback failed } .