Results 1 to 3 of 3

Thread: endl & \n character not working in output stream?

  1. #1
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: endl & \n character not working in output stream?

    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:
    Qt Code:
    1. #include <stdio.h>
    2. #include <math.h>
    3. #include <QList>
    4. #include <QFileDialog>
    5. #include <QFile>
    6. #include <fstream>
    7. #include <iostream>
    8. #include <iomanip>
    To copy to clipboard, switch view to plain text mode 

    My outputting statement:
    Qt Code:
    1. stream << array1[m] << "\t" << array2[m] << endl;
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by ebsaith; 14th June 2013 at 10:15.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: endl & \n character not working in output stream?

    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,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: endl & \n character not working in output stream?

    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.

Similar Threads

  1. endl' was not declared in this scope
    By k.qasempour in forum Newbie
    Replies: 8
    Last Post: 21st June 2012, 09:36
  2. Display an output buffer (text stream) in QWidget
    By nomiz in forum Qt Programming
    Replies: 8
    Last Post: 30th June 2011, 09:44
  3. Application Output : MediaSource::Stream not yet handled
    By hrn2k1 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 6th April 2011, 06:19
  4. NUll character output for combobox index
    By mdskpr778 in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 18:22
  5. stray character in gcc output
    By Gopala Krishna in forum General Discussion
    Replies: 5
    Last Post: 13th October 2007, 18:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.