Thread: expected primary -expression before '}' token }

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    2

    expected primary -expression before '}' token }

    Code:
    #include <iostream>
    #include <fstream>
    #include "pass.h"
    
    
    using namespace std;
    
    
    class data{
    
    
    public:
        struct student
        {
            char name[20];
            int clas;
            char city[20];
            int admno;
     
        };
    
    
        student s;
       
    
    
        void add(){
            char ch='Y';
            ofstream outfile;
         outfile.open("STUDENT.DAT", ios::out | ios:: binary);
    
    
         cout<<endl<<"Enter a record:name |  class | city |  admissionno\n";
         while(ch=='Y' || ch=='y')
         {
          
              cin>>s.name>>s.clas>>s.city>>s.admno;
    
    
              outfile.write((char*)&s,sizeof(s));
              cout<<endl<<"Add another y/n"<<endl;
              cin>>ch;
          }
    
    
          outfile.close();
          }
    
    
    
    
        void disp(){
            ifstream infile;
             infile.open("STUDENT.DAT",ios::in | ios::binary);
    
    
             while(infile.read((char*)&s,sizeof(s)))
            {
              cout<<endl<<s.name<<"\t"<<s.clas<<"\t"<<s.city<<"\t"<<s.admno<<endl;
            }
           }
    
    
        };
    
    
    int main()
        {
          data d;
           fstream outfile;
           outfile.open("STUDENT.DAT", ios::in |ios::out | ios:: binary |ios::app); 
    
    
           getpass();
           system("CLS");
    
    
          int c;
           cout<< "input c-";
           cin>>c;
           switch(c){
    
    
            case 1: d.add();
             break;
    
    
            case 2: d.disp();
            break;
           
            default:
           }
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2017
    Posts
    2
    plz somebody explain this erroe
    i gotta submit this plz

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Your default needs to actually do something, even if that something is nothing.

    Perhaps like this.
    Code:
    #include <iostream>
    #include <fstream>
    //#include "pass.h"
    
    using namespace std;
    
    class data {
    public:
      struct student {
        char name[20];
        int clas;
        char city[20];
        int admno;
      };
      student s;
      void add() {
        char ch = 'Y';
        ofstream outfile;
        outfile.open("STUDENT.DAT", ios::out | ios::binary);
        cout << endl << "Enter a record:name |  class | city |  admissionno\n";
        while (ch == 'Y' || ch == 'y') {
          cin >> s.name >> s.clas >> s.city >> s.admno;
          outfile.write((char *) &s, sizeof(s));
          cout << endl << "Add another y/n" << endl;
          cin >> ch;
        } outfile.close();
      }
      void disp() {
        ifstream infile;
        infile.open("STUDENT.DAT", ios::in | ios::binary);
        while (infile.read((char *) &s, sizeof(s))) {
          cout << endl << s.name << "\t" << s.clas << "\t" << s.
              city << "\t" << s.admno << endl;
        }
      }
    };
    
    int main()
    {
      data d;
      fstream outfile;
      outfile.open("STUDENT.DAT", ios::in | ios::out | ios::binary | ios::app);
     // getpass();
      system("CLS");
      int c;
      cout << "input c-";
      cin >> c;
      switch (c) {
      case 1:
        d.add();
        break;
      case 2:
        d.disp();
        break;
      default:
        ;
      }
      return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error : expected primary-expression before ']' token
    By funnydarkvador in forum C Programming
    Replies: 8
    Last Post: 02-20-2013, 07:06 PM
  2. error : expected primary-expression before ']' token
    By funnydarkvador in forum C++ Programming
    Replies: 8
    Last Post: 02-20-2013, 07:06 PM
  3. expected primary-expression before xxx token
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 07-06-2009, 02:54 PM
  4. expected primary expression before "." token
    By melodious in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 04:39 AM
  5. Expected primary expression before '<<' token...
    By RpgActioN in forum C++ Programming
    Replies: 3
    Last Post: 08-05-2005, 10:40 PM

Tags for this Thread