Wing Hang Khoo
Wing Hang Khoo

Reputation: 41

endl not creating new line in output file

This is my code now

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{

// set up input file
ifstream lInput;    // declare an input file variable (object)
ofstream lOutput;
lInput.open(argv[1], ifstream::binary); // open an input file (binary)
lOutput.open(argv[2], ofstream::binary);
if (!lInput.good())
{
    // operation failed
    cerr << "Cannot open input file " << argv[1] << endl;
    return 2;       // program failed (input)
}

lOutput << "test" << endl;
lOutput << "test2" << endl;

My current output is

testtest2

How do I make it to

test

test2

Thankyou for your help

edit: test to "test" and test2 to "test2" edit2: lOutpt to lOutput

Upvotes: 1

Views: 1276

Answers (1)

Pete Becker
Pete Becker

Reputation: 76305

C and C++ have two types of files: text and binary. Binary files are not text. They don't have lines, so they don't have line endings. If you want to talk sensibly about line endings and other text-related things, use a text file.

Upvotes: 3

Related Questions