Is there a way to set istream buffer content? I need to write string into std::cin in other way than user's input. I've tried with putback() but it only works with one char.
Putback or unget is a conveniece for parsers that need to peek into the stream to see the next character to decide whether to continue or not. The data only goes back into a buffer, not all the way back to the source.
I have almost complete program for parsing expressions, where expression is parsed from std::cin in 5 different classes. I need to add option for parsing expression which doesn't come from user's input, but from some defined source (file for example). It will be much easier for me to just write value into cin than rewriting whole parsing.
Thx Galik, Im already writing something similar, but it still requires rewriting part of the project. I hoped for solution which requires one or two lines of code.
Well hopefully you just need to replace your std::cin with a reference to a std::istream throughout. It might be a bit of work, but its the 'right thing to do' ;o)