//the code below from a tutorial is demonstrating the usefulness
//of the function getline() when entering strings with whitespaces.
#include <string>
#include <iostream>
int main()
{
std::cout << "Enter your full name: ";
std::string name{};
std::getline(std::cin >> std::ws, name); // read a full line of text into name
std::cout << "Enter your age: ";
std::string age{};
std::getline(std::cin >> std::ws, age); // read a full line of text into age
std::cout << "Your name is " << name << " and your age is " << age << '\n';
return 0;
}
I run and compile with Visual Studio (with run in terminal checked in settings) and the input/output behaves as I would expect.
But with Eclipse CDT: After running there is nothing in console. If I type, "John Doe" FIRST then hit enter only then I am prompted to enter name. But following what I input is 'formatted' into variable "age" not variable "name" in std::cout << "Your name is " << name << "and your age is" << age << '\n';
taking some liberties here it goes as represented below.
(nothing in console), my input: "John Doe".
"enter your name", my input: "20".
"enter your age Your name is John Doe and your age is 20."
I try std::cerr and just get a "enter your name" but the program does nothing after I hit enter.
My lack of understanding in this trivial regard is really messing with me.
It appears the buffer (my uneducated guess) and the console output are not synchronized properly but why is this?