Reading in a line.

This is a discussion on Reading in a line. within the C++ Programming forums, part of the General Programming Boards category; What I'm trying to do is read in each line from a file in the format of <char><blank><number, with char ...

  1. #1
    Registered User carrja99's Avatar
    Join Date
    Oct 2002
    Posts
    56

    Reading in a line.

    What I'm trying to do is read in each line from a file in the format of <char><blank><number, with char being read even if it is blank. The following code worked fine with while(read >> c), except in the instance that c was a blankspace.

    Code:
    while(read.get(c))
    		{
    		a[size] = c;		    // read char into array	
    		sort_array(a, size);	    // keep array sorted.	
    		read.get();                 // get the next char, which should be ' '
    		read >> v;                  // read the frequency number		
    		add_list(root, list, v, c); // add the node to the list
    		size ++;   		    // increment size
    		}
    I am Error. When all else fails, use fire.

    My Current Screenshot

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Code:
    while ((read >> c >> v).good()) {
      // blah blah blah
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-19-2009, 12:44 AM
  2. Replies: 1
    Last Post: 05-21-2006, 12:17 AM
  3. Replies: 6
    Last Post: 04-28-2006, 01:06 PM
  4. Reading a user specificed line from a file
    By hslee16 in forum C++ Programming
    Replies: 3
    Last Post: 03-13-2004, 06:58 PM
  5. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM

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