Results 1 to 3 of 3

Thread: reading/writing to file

  1. #1
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question reading/writing to file

    hi

    I have a file with this structure:

    15 12 36
    25 45 36
    12 48 20

    i used out << int1 << "\t"<<int2 << "\t"<<int3 <<endl; to write it;

    but when i use

    in >> int11 >> int12 >>int13; i do not have correct results

    what can i do?
    Last edited by QiT; 8th August 2006 at 08:42.

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading/writing to file

    I would recommend reading one line at a time and splitting it on tabs (pretty much as is done in this example, only that it is splitting on colons http://doc.trolltech.com/3.3/tutorial2-03.html - look for the implementation of operator>> )

  3. #3
    Join Date
    Aug 2006
    Posts
    27
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading/writing to file

    Also posible:

    Qt Code:
    1. out << int1 << "\t"<<int2 << "\t"<<int3 <<endl;
    2. in >> int1;
    3. in >> int2;
    4. in >> int3;
    To copy to clipboard, switch view to plain text mode 

    That's how I would do it.
    Or:

    Qt Code:
    1. QStringList tsTemp;
    2. QString sTemp;
    3.  
    4. out << int1 << "\t"<<int2 << "\t"<<int3 <<endl;
    5. sTemp = in.readLine();
    6. tsTemp = sTemp.split("\t");
    7. int1 = tsTemp.at(0);
    8. int2 = tsTemp.at(1);
    9. int3 = tsTemp.at(2);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    Bart.

  4. The following 2 users say thank you to windkracht8 for this useful post:

    ak (21st August 2006), QiT (12th August 2006)

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  2. .ui file name and classname
    By Rekha in forum Newbie
    Replies: 3
    Last Post: 12th August 2006, 01:53
  3. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24
  4. QHttp GET File & Password
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 11th June 2006, 13:04
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

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.