PDA

View Full Version : endl & \n character not working in output stream?



ebsaith
14th June 2013, 11:15
Good Day,

I'm outputting an Array to a text file.
Output works except for the formatting of a new line!

I'm not sure if I'm missing any #include

This is what I got:


#include <stdio.h>
#include <math.h>
#include <QList>
#include <QFileDialog>
#include <QFile>
#include <fstream>
#include <iostream>
#include <iomanip>


My outputting statement:


stream << array1[m] << "\t" << array2[m] << endl;


the tab "\t" works
when I try either <<endl or "\n"
No new lines are created in text file

Any Ideas?
Thanks

Added after 1 27 minutes:

Apologies--- Was not Qt Problem
Apparently notepad does not pick up newline character when displayed!
Notepad++ displayed correctly -> #Learned colleague showed me the diff

Kind Regards

anda_skoa
14th June 2013, 12:20
Notepad is a very old piece of Windows software, it can only deal with "Windows" line endings and those are "\r\n" not it doesn't interpret "\n" alone as a newline.
Any more recent editor, even wordpad, can do that correctly :)

Cheers,
_

ChrisW67
15th June 2013, 00:39
A standard C++ stream in text mode should be converting "\n" to/from "\r\n" as you write/read the stream on Windows. If the stream is written on a UNIX-like machine or in binary mode (std::io_base::binary) then the '\n' character will be read/written verbatim.