Streams - sheerazwalid/COMP-I GitHub Wiki
identifier | description | redirect from/to file |
---|
cin | standard input stream; keyboard by default | `./a.out < file.txt`
cout | standard output stream; console by default | ./a.out > file.txt
(use >> to concatenate)
cerr | standard error stream; console by default | ./a.out 2> file.txt
#include <iostream>
using namespace std;
int main() {
cout << "Enter an integer: ";
int n;
cin >> n; // This will extract an integer from the input stream and copy into n.
cout << "Enter a floating point number: ";
double x;
cin >> x; // This will extract a double from the input stream and copy into x.
char newlineChar = cin.get(); // Remove the unread new line character.
cout << "Enter a line with spaces between words:" << endl;
string s;
getline(cin, s); // This will extract characters until end of line or end of file and copy into s.
return 0;
}