I'm trying to write a .dat file using Windows subsystem for Linux, but the fstream library seems to bypass every endline command. Here is my code:
int main()
{
string fname = "DataSheet.dat";
ofstream fdata (fname.c_str(), ios::out);
fdata << "First line" << endl;
fdata << "Second line" << endl;
fdata.close();
return = 0;
}
I tried substituting << endl
with << "\n"
and modifying the ofstream command like showed there, but nothing worked; the output was always First lineSecond line
instead of First line
and Second line
on subsequent lines.
Besides, the code works perfectly well when I print the output to video using cout
command or when I compile and run it on cygwin.
Is it a problem of Windows subsystem for Linux or am I missing something important?