Reputation: 1532
I'm trying to create a very simple chat application where a user types something in (received by cin) and I echo their output manually, but cin naturally prints to console after the user hits enter on the keyboard.
Is there a way to suppress this echo back into cout after the user returns from cin so I can override it with my own message?
Ex:
int main()
{
string str;
while(true)
{
getline(cin, str)
cout << "Person: " << str << endl;
}
}
The output looks like this:
Some text I typed
Person: Some text I typed
The first line is automatically echoed back into the terminal when the user sends the new line. This is the line I would like to suppress.
Any ideas? I am trying to stay away from using any 3rd person library if possible.
Upvotes: 1
Views: 1196
Reputation: 100
As far as I know this is not possible on standard C++ without using any 3rd party libraries. If you are willing to use OS specific libraries, then this link or this one might help. This is unfortunately not an option in native C++ because it is up to the OS to decide how it handles the console output (hence why for exemple you need OS specific solutions for advanced console stuff like colors).
Upvotes: 2