Reputation: 1763
What I am trying to do is to have a pointer pointing to user input without creating extra variable. Something like this:
system("CLS");
cout << endl << "Please enter your expression:" << endl;
*expression->infix = &cin>>;
Obviously this doesn't compile, is there any way of doing something like this without creating an extra variable for storing the user input and then pointing to it?
Upvotes: 0
Views: 223
Reputation: 18898
cin
is an istream
representing the standard input of the OS. In Linux, for example, reading from a stream entails issuing the read
syscall. The input might not even be typed yet, and even if it is, it would most likely be buffered in kernel memory until you read it. So there is no way for you to point into this memory. The best you can do is to read it into user-space memory and point into that memory.
EDIT: to clarify I would line to add that the istream
might have an additional internal buffer in your process's memory for performance reasons (see rdbuf
). But you wouldn't want to point into that buffer even if you could, since its data would be changed over time as data is passing through the stream.
Upvotes: 3