I am trying to put a cout and a cin on the same line as so cout << "Person 1:" << cin >> int p1;. Does anybody know a way that I could do the same thing successfully?
I'm using C++ on repl.it if that helps
The code you showed will not work, because you can't pass a std::istream (like std::cin) to operator<< of a std::ostream (like std::cout). You need to separate the expressions, separating them by either:
a semicolon (Live Demo):
int p1;
cout << "Person 1:";
cin >> p1;
the comma operator (Live Demo):
int p1;
cout << "Person 1:", cin >> p1;
You can write:
int p1 = (cin >> (cout << "Person 1: ", p1), p1);
This would be a terrible idea in terms of writing clear code, I'm mainly posting it in response to several others who said that it is not actually possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With