Thread: Need help formatting data from a text file.

  1. #1
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605

    Need help formatting data from a text file.

    Alright, so here's what I have:

    Code:
    ifstream op1appt;
                                        op1appt.open("op1appts.txt");
                                        if(!op1appt.is_open())
                                        {
                                                               cout<<"Could not load file.\n";
                                        }
                                        else
                                        {
                                            system("cls");
                                            while(!op1appt.eof())
                                            {
                                                                 op1appt.getline(op1adata,256);
                                                                 cout<<op1adata;
                                            
                                            }
                                        }
    The problem here is that its putting all the text from the file into one big long line. I need it to reflect the formatting of the file, meaning line 1 of the file goes to line 1 of the screen, so on and so forth.

    I understand that the 'char' variable wont support the formatting, but what can I do to prevent having a seperate variable for each line? I've been looking all over for a tutorial on how to do this, and im sure ive seen it in the past, but i've come up dry.

    Thanks in advance for your help!
    .

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You could print out a new line at the end of every line read in.

  3. #3
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    Wow. Cant believe I didnt think of that before. Thanks.
    .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Reading data from a text file
    By Dark_Phoenix in forum C++ Programming
    Replies: 8
    Last Post: 06-30-2008, 02:30 PM
  3. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  4. Using fscanf for reading numerical data from text file
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 06-15-2002, 05:18 PM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 11:47 AM