Is it possible to edit the cin input buffer?

Is it possible to start a cin that already has text in it? So like the input buffer already contains characters before the user types anything in.
Not really, the std::cin object is created in the iostream header, and AFAIK the constructor for istream objects doesn't take arguments. What are you trying to do? There is probably a better solution. Also streams really only save formatting data, they are there to interact with the hardware input.
See, I want to make a very simple editor in the console, so I want to have an editable string to begin with, if you could give me any pointers that would be great.
I'd just make a stream.
If you don't mind me asking, how would you do that?
Use a stringstream.
There is one other way!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class mystream
{
	stringstream stream;
	public:
	template<typename T>
	istream& operator>>(T& x)
	{
		return stream.str().empty()?cin>>x:stream>>x;
		}
	template<typename T>
	ostream& operator<<(const T& x)
	{
		return stream<<x;
		}
} myin;

Now, when you use myin<<x, it will put x into the input buffer! That way, myin>>x will read from cin iff the buffer ins empty, and from the buffer otherwise! I think that's just what you wanted! :D
bump
what are you bumping it for, and you sure do love templates
Thanks viliml, workarounds are somewhat of an art
Topic archived. No new replies allowed.