Thread: Text file

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    Question Text file

    I've got a text file that I need to output to the screen. The text file contain's blank lines, which also need to be outputted to the screen. The code which i'm using at the mo is:

    Code:
    while(!File.eof())
    {
      File.getline(Buffer,100)
      cout << Buffer;
    }
    
    File >> ws;
    getchar();
    Getline is just ignoring blank lines, and going onto the next bit of data.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Are you sure? Try a newline on your cout to be sure.

    cout << Buffer << endl;

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Tried a new line, still does the same. Debugger shows getline ignoring the any blank lines.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    getline's default deliminating character is \n
    instead try file.getline(Buffer, 100, EOF);
    not sure if EOF can be used this way or not

  5. #5
    Unregistered
    Guest
    /*file*/

    8/8/2002

    1 2 3 4

    //reading file
    char filename[] = //whatever;
    ifstream fin(filename);
    char ws;
    char buffer[12];
    int array[4];

    while(!fin.eof())
    {
    fin.getline(buffer, 11);//ignore newline at end of first line
    fin >> ws;//store second new line in ws
    for (int i = 0; i < 4; i++)
    {
    fin >> array[i];
    }
    }

    or read entire file in one char at a time

    char ch;
    char buffer[50];
    int i = 0;
    while(fin.get(ch) && i < 50)
    {
    buffer[i++] = ch;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM