Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ ofstream line break

Tags:

This is my code:

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    ifstream ifile ("input.dat", ios::in);
    ofstream ofile ("output.dat",ios::out);

    int num;
    ifile >> num;
    ofile << num;
    ofile << endl;
    ofile << "Did we go to new line?";
    ofile << endl;

    return 0;
}

The problem is, everything in output.dat is on the same line. How can I resolve this?

Thanks!

EDIT: I was using Windows to see the files and Linux to compile. This is why I was running into this issue. Using cat output.dat on the Linux side to see the file contents would have revealed that Windows vs. Linux line breaks are different at the time.