Thread: Flush !!

  1. #1
    Registered User
    Join Date
    Oct 2002

    Flush !!

    While reading data from a file to be loaded into an array, if an error occurs ont he 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....

    fsinventoryFile>> invArray[index].itemCode;
    while(!fsinventoryFile.eof() )
          fsinventoryFile >> invArray[index].quantity
                                  >> invArray[index].price;
          while((!invArray[index].price ) || (!invArray[index].quantity))
    	while(cin.get(aCh) && aCh !='\n');
    	cout <<"Invalid input on: " 
         cout<<"Record " <<index << " item code is:\t " 
                <<invArray   [index].itemCode <<endl;
         cout<<"Record " <<index << " quantity is:\t " 
         cout<<"Record " <<index << " price is:\t " 
         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
    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:
    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,

    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
    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, 02: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, 09: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