Results 1 to 12 of 12

Thread: Write one value per line in text file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question Write one value per line in text file

    Code :
    Qt Code:
    1. QString filename = "textfile.txt";
    2. QFile file(filename);
    3. QString val;
    4. float v;
    5.  
    6. if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
    7. {
    8. for ( int i =0; i<Results.localresults.size() ; i++)
    9. {
    10. v = Results.localresults.at(i);
    11. val = QString::number(v);
    12. char *valtoAsciidata = val.toAscii().data();
    13. QTextStream out(&file);
    14. out << v << endl ;
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    I have written code as above to actually write values to a text file. But it writes the values continuously . What I want is one value to be written in one single line, then the next value on the next line.
    How to code in such a way that it writes one value per line ?
    Last edited by babygal; 29th November 2010 at 08:19.

Similar Threads

  1. How to write ByteArray into a text file?
    By babygal in forum Newbie
    Replies: 4
    Last Post: 11th October 2010, 04:19
  2. Remove a line in a text file
    By jaca in forum Newbie
    Replies: 1
    Last Post: 18th March 2010, 22:13
  3. How to read line number in a text file
    By grsandeep85 in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2009, 09:09
  4. How to write something in line of txt file
    By Zergi in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2007, 10:02
  5. Replies: 2
    Last Post: 17th November 2006, 11:25

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.