#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
cout << "Hello World!";
}
This isn't working. Why?
get() extracts that newline from the stream, and the second wait waits for input because the stream is now empty. If you had only the one cin. get() call, it would extract the newline immediately and continue, and since there is nothing after that cin. get() call, the program terminates (as it should).
Inputting a string You can use cin but the cin object will skip any leading white space (spaces, tabs, line breaks), then start reading when it comes to the first non-whitespace character and then stop reading when it comes to the next white space. In other words, it only reads in one word at a time.
On Windows you'd use Ctrl-Z, on UNIXes you'd use Ctrl-D.
Because you forgot to #include <string>
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