Results 1 to 3 of 3

Thread: Problem: Reading and editing text file data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    New Delhi, India
    Posts
    31
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Post Problem: Reading and editing text file data

    I have a text file having data something like:

    ww1
    ww2
    ww3
    ww4
    I want to search for a particular string in this file, so i am reading this file. When the word is found say "ww3" , i wish to edit that entry to something like $$ww3 or ( add anything). I tried using pos() and seek(), but it's deleting all text data from file leaving one or two chars.

    I would like to know some way to do this. Please help.

    Thanks in advance.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem: Reading and editing text file data

    Rewrite the entire file:

    (Psuedocode, you would use QFile for this)
    Qt Code:
    1. while (!eof(file))
    2. {
    3. str = readlinefromfile();
    4. if (str == "ww3") writelinetofile("$$ww3"); else writelinetofile(str);
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to squidge for this useful post:

    dipeshtech (2nd May 2011)

Similar Threads

  1. Reading from text file
    By jerkymotion in forum Qt Programming
    Replies: 5
    Last Post: 17th March 2011, 11:26
  2. Replies: 1
    Last Post: 27th January 2011, 09:19
  3. Editing text file via console app
    By cejohnsonsr in forum Newbie
    Replies: 1
    Last Post: 30th August 2010, 21:39
  4. Reading data from xls file
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2010, 09:33
  5. reading data from file
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2010, 10:31

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.