Thread: compiler skips one statement

  1. #1
    Unregistered
    Guest

    Question compiler skips one statement

    #include<fstream.h>
    #include<stdio.h>
    void main()
    {
    char name[20];
    int marks;
    char c;
    ofstream fwrite("vin.txt");
    cout<<"Enter name: ";
    cin.getline(name,20);
    cout<<"Enter marks: ";
    cin>>marks;
    fwrite<<name;
    fwrite<<marks<<endl;
    cout<<"Enter name: ";
    fflush(stdin);
    cin.getline(name,20);/**problem...compiler skips this statement...**/
    cout<<"Enter marks: ";
    cin>>marks;
    fwrite<<name;
    fwrite<<marks<<endl;
    }

    if i use cout instead of getline..the statement is executed...and also the first getline statement isnt skipped.
    What might be the reason??

  2. #2
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    remove fflush(stdin);

    As far as i know you don't need it. It's purpose is to flush (write to the file stream) it's contents. Also I believe it only accepts as an argument a file stream.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    try cin.ignore()
    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. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. Comile problem using latest Dev C++ Compiler
    By shiny_dico_ball in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2003, 05:32 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM