Thread: How keep multi-row *.txt form?

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    12

    How keep multi-row *.txt form?

    Hello all:

    I have a *.txt file like:

    20121001 Chang $55.5
    20121002 Zhang $60.0
    20121003 Pan $50.01

    I tried to use iftream to read it into program and display in the same form. BUT failed. Because the file has spaces separate the items.

    What is the way to read them and display in the same form?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    if you use std::getline() (not std::istream::getline()), you can get whole lines of text from the file, and keep their format.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    If the number of columns is fixed, you could alternatively read everything using the extraction operator (>>). However, the approach with std::getline() is probably better, especially if you decide to make the number of columns variable.
    If you want your stream to operate on memory (to split line obtained by std::getline()), you can use std::istringstream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows form C++ - referencing the form
    By rocketman50 in forum Windows Programming
    Replies: 2
    Last Post: 05-22-2010, 11:58 AM
  2. Accessing Controls on a different form from one form.
    By Tperry23 in forum C# Programming
    Replies: 7
    Last Post: 06-09-2005, 06:13 PM
  3. How to build Multi Form?
    By NightWalker in forum Windows Programming
    Replies: 2
    Last Post: 05-08-2004, 09:08 AM
  4. Multi-Form?
    By NightWalker in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2004, 01:27 AM
  5. long form of year to short form?
    By bc120 in forum C Programming
    Replies: 2
    Last Post: 12-31-2001, 05:34 PM