1

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

Community
  • 1
  • 1
Wing Hang Khoo
  • 41
  • 2
  • 10
  • It is ALWAYS better to post the actual code you use. That way you remove the typos an undefined stuff that you question now has too much of. – Jonas Mar 28 '17 at 04:52
  • How are viewing the output file? You could change `lOutput.open(argv[2], ofstream::binary);` to `lOutput.open(argv[2]);` to see if that makes a difference. – R Sahu Mar 28 '17 at 04:54
  • Related: http://stackoverflow.com/a/8281481/4926357. Don't use `<<` with binary streams. – A.S.H Mar 28 '17 at 05:09

1 Answers1

3

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.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165