[not really] QFile open for append adding extra newline 8-(



  • This seems like it should be so easy 8-(

    I have a text file, something like this:
    @
    line1
    line2
    line3
    @

    There is no empty line at the end.

    I open the file in append mode and create a QTextStream.

    @
    QFile file(filename);
    file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
    QTextStream out(&file);
    @

    If I write without inserting '\n' (or endl) the text goes right on the of the last line:

    @
    out << "line4";
    @

    The file now looks like this:
    @
    line1
    line2
    line3line4
    @

    However if I insert '\n' (or endl) there is always an empty line between the previous EOF and the line I append:

    @
    out << endl << "line4";
    @

    The file now looks like this:
    @
    line1
    line2
    line3

    line4
    @

    Is there some way to append without creating this extra empty line?

    Thanks for any tips!!!

    johnea



  • This was VIM's fault 8-(

    It adds an EOL at the end that it doesn't show.

    You can prevent this by using ":set binary"

    Sorry, Operator error...

    johnea


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.