#include <fstream>;
using namespace std;
int main(){
ofstream outFile("myFile.txt");
outFile << "ECE" << endl;
outFile << "244" << endl;
outFile.close();
return 0;
}
The above example will flush to the file after “ECE” and also “244”. If we want to flash at the end, we can do two things: we can do the endl; or we can do flush().
#include <fstream>;
using namespace std;
int main(){
ofstream outFile("myFile.txt");
outFile << "ECE";
outFile << "244";
outFile << endl;
}
#include <fstream>;
using namespace std;
int main(){
ofstream outFile("myFile.txt");
outFile << "ECE";
outFile << "244";
outFile.flush();
}
int x, y;
cin >> x >> y;
101\\n75\\n
101 is read until it sees the \\n, so the 101 is saved into x75 is read until it sees the \\n, so the 75 is saved into y\\t and \\nint x, y;
cin >> x >> y;
13. 37
13 is scanned with no issue in to xcin cannot skip a ., but it’s still trying to save an integer into y, so we have an errorSummary:
cin will read 13 into x, but it will not read . into y as it is not an integer.cin will fail silently.y is not affected (its value wasn’t scanned and changed), and the buffer is not affected.cin is failing. This will affect all cin in the program unless we solve the issue.
cin.fail() = 1 if errorcin.fail() = 0 if no error