Thread: Reading in a line.

  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-18-2009, 11:44 PM
  2. Replies: 1
    Last Post: 05-20-2006, 11:17 PM
  3. Replies: 6
    Last Post: 04-28-2006, 12: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