Input and output is ACTUALLY a complicated task. Thankfully, the standard library
There are these weird lil characters you can't "see". For example, a new line or the tab key. To specifically say these characters, we first use the "escape character" or in C++, the '\'. If we want to say "tab" character, we say '\t'. The compiler will know to treat those two characters as one. For now, the resource linked above has a full list of those special characters.
Input is simple. But you also need to put the data you get somewhere, hence
variables. Just as
#include <iostream>
#include <string>
using namespace std;
int main() {
string input_string;
cout << "type something in plox:";
cin >> input_string; //ask the user for input and store it in 'input_string'
cout << "you said:" << input_string; << endl;
return 0;
}
Type something in plox: hablabla
you said: hablabla
|
Again, because cin stops at any whitespace, we'll need a helper to ignore it.
getline (cin,input_string);
The "cin" part of getline is there because you're telling it where to listen from.
The second part is where you want it to store the information it collected.