I have the following C++ code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
fstream file;
file.open("file.txt", fstream::in | fstream::out | fstream::app);
file << "Ivan" << "\n" << "Ivan";
string text = "";
while (!file.eof()) {
text = "";
file >> text;
cout << text;
}
file.close();
}
When I'm using cout
to print that text to console, this gives me lots of white lines. And when I enter the .txt file, there are lots of "H" letters except for my text. I think the problem is in the loop.
Does somebody know what the problem is?