I have a function that reads user input from std::cin, and I want to write a unittest that inserts some strings into std::cin, such that later extraction from std::cin will
cin.putback() is guaranteed to work with at most one character, so you can't putback a whole string. Use a stream that wraps cin and allows arbitrary putback() sequence length. I think Boost.Iostream have something similar, and if it doesn't then it might be helpful to implement such a wrapper.