Converting integer data from text file

This is a discussion on Converting integer data from text file within the C++ Programming forums, part of the General Programming Boards category; I have a data conversion question. I'm trying to read a very large space-delimited .txt file (almost 1 million records) ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    Converting integer data from text file

    I have a data conversion question. I'm trying to read a very large space-delimited .txt file (almost 1 million records) and convert the data into a different format, but I can't figure out how best to do it. I don't have much experience reading data from a file.

    The data is stored like this...

    Code:
     
    1 1 
    2 
    3 2 2 4 2 2 2 3 3 
    5 
    1 
    6 
    1 1 
    6 
    6 7 7 7 6 6 8 8 8 8 
    6 9 4 4 4 10 3 10 5 10 4 4 4
    and I want it to convert to this...

    Code:
     
    1
    2
    2 3 4
    5
    1
    6
    1
    6
    6 7 8
    3 4 5 6 9 10
    where the existing entries for each record appear in ascending order with no dupilcates. All of the entries are integers between 1 and 17. Each line is a separate record.

    I need the new output to be stored in a new .txt file.

    I'm sure there's some SQL commands that would probably be easier, but I'm a new programmer and don't have experience with anything outside of C++.

    Any suggestions you could give would be greatly appreciated.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If each line is independent of every other line, then you shouldn't try to process more than one line at a time.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    1. Read a line from the file.
    2. Parse individual numbers out of the line and insert them into a set<int> container.
    3. Output contents of set<int> container to new file.
    4. Rinse, repeat.
    5. ...
    6. Profit!


    The set container will automagically take care of removing duplicates and sort from least to greatest for you.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21