file read

This is a discussion on file read within the C++ Programming forums, part of the General Programming Boards category; Code: int main( int countc, char *argv[]) { ifstream in("input.txt"); char c; while(in>>c) { if(c == '\n') cout << "\n"; ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,703
    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, 01: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, 01:58 AM

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