Talk:cpp/io/basic istream/putback
From cppreference.com
I have implemented this program to understand more `cin.putback();`:
std::string str;
while( std::cin.peek() != EOF){
if( std::cin.get() == '*')
std::cin.putback('$');
else
std::cin.unget();
str += std::cin.get();
}
Input:
Hello***There!
output:
Hello$$$there!
- The program looks to work fine but in my case I extract '*' as the last character read but calling std::cin.putback('$') in which case they are not identical characters. And in the text above it is said that "...takes an argument that must be the same as the one that was last read."
So could you please clarify it? — Preceding unsigned comment added by Raindrop7 (talk • contribs)