Flush !!

This is a discussion on Flush !! within the C++ Programming forums, part of the General Programming Boards category; While reading data from a file to be loaded into an array, if an error occurs ont he input....an error ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    22

    Flush !!

    While reading data from a file to be loaded into an array, if an error occurs ont he input....an error message should be displayed and the rest of the line should be flushed....and continue on with the next line.....the code I wrote is....

    Code:
    fsinventoryFile>> invArray[index].itemCode;
    
    
    while(!fsinventoryFile.eof() )
    {
    		
    		
          fsinventoryFile >> invArray[index].quantity
                                  >> invArray[index].price;
    
          while((!invArray[index].price ) || (!invArray[index].quantity))
          {
    	cin.clear();
    	while(cin.get(aCh) && aCh !='\n');
    	cout <<"Invalid input on: " 
                            <<invArray[index].itemCode<<endl;
          }
         cout<<"Record " <<index << " item code is:\t " 
                <<invArray   [index].itemCode <<endl;
         cout<<"Record " <<index << " quantity is:\t " 
                <<invArray[index].quantity<<endl;
         cout<<"Record " <<index << " price is:\t " 
                <<invArray[index].price<<endl;
    	
         index++;
    
         fsinventoryFile>> invArray[index].itemCode;
    
    
    }//end of while loop
    any help on this would be great....thx

    Code tags added by kermi3

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. I also suggest you take a look at the board guildlines if you have not done so already. Any further questions or ways I can help please feel free to PM me.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    Good Luck,
    Kermi3
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with input flush
    By KarrieWojo in forum C Programming
    Replies: 12
    Last Post: 12-29-2007, 01:38 AM
  2. endl - \n
    By Hugo716 in forum C++ Programming
    Replies: 8
    Last Post: 05-25-2006, 02:33 PM
  3. flush socket
    By Snip in forum Networking/Device Communication
    Replies: 17
    Last Post: 02-08-2005, 08:29 PM
  4. How do I print a pattern flush right?
    By Basia in forum C Programming
    Replies: 5
    Last Post: 06-11-2002, 07:15 AM
  5. Can someone xplain FLUSH in strings?
    By aspand in forum C Programming
    Replies: 9
    Last Post: 05-13-2002, 12:10 AM

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