Thread: file read

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    file read

    Code:
    int main( int countc, char *argv[])  {
                   ifstream in("input.txt");
                  char c;
                  while(in>>c)    {
                            if(c == '\n')
                            cout << "\n";
                            cout << c;
                    }
    }
    this is my code
    input file is
    Code:
    1, a, 2
    1, d, 4
    3, b, 2
    3, c, 4
    5, e, 4
    output is:
    Code:
    1,a,21,d,43,b,23,c,45,e,4
    I have two query:
    1. why it is not reading blank spaces or '\n'?
    2. what to modify to read blank spaces and 'n' both?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    1. It's supposed to skip white space.
    2. Use the 'noskipws' stream modifier found in <iomanip>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Handling -Read write and edit a file
    By aprop in forum C Programming
    Replies: 3
    Last Post: 02-27-2010, 02:01 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM