String Problem !!

Hi all,
I am new to C++. I wrote a code. The problem is that I am not able to give a string as input. Whenever i press ENTER after giving my admission number then the program jumps straight to "Do you want to add another (Y/N) ?". The program simply displays "Enter the name of the student :", but does not take in any input. Please help me solve my problem.

#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <cstdlib>

using namespace std;

class student
int admno;
char name[50];
char another;
int choice;
long int recsize;

} so;

recsize = sizeof(so);
ofstream fp1("student.dat",ios::binaryios::app);
ifstream fp2("student.dat",ios::binary);
cout << "********************Welcome to ADMISSION MANAGEMENT SYSTEM********************" << endl;
cout << "1. New Entry." << endl;
cout << "2. View Registered Entries." << endl;
cout << "3. Modify Existing Entry." << endl;
cout << "4. Delete Existing Entry." << endl;
cout << "5. Exit." << endl << endl;
cout << "Make Your Choice : ";
choice = getch();
case '1':
another = 'Y';
while(another == 'Y' another == 'y'){
fp1.write((char*)&so, recsize);
cout << "********************Enter Details********************" << endl;
cout << "
Enter The admission no. ";
cin >> admno;
fp1 << admno;
cout << "

Enter The Name of The Student :";
cin.getline(name, 50);
fp1 << name;
cout << "Do you want to add another (Y/N) ? ";
cin >> another;
case '2':
cout << "********************Registered Students********************" << endl;
while(*)&so, recsize)){
Admission no. : ";
fp2 >> admno;
cout << admno << endl;
Student Name : ";
fp2.getline(name, 50);
cout << name << endl;

int main(){
return 0;
I think you've written the code out of the main function

it is normal to do this?
Last edited on
the main function is empty.
I dont know whether its normal or what if main function is empty....should i write something in main function ??
main is the entry point of your program.

If it's empty, nothing will happen when your program runs.
You haven't specified the return type of the function student(). You haven't written anything in your main() function. Nothing should happen when you compile this program. There are too many errors in your code. You didn't even close the function braces properly. Why is there second semicolon at the point where the function ends? Did this code even compile? Which compiler are you using?
Topic archived. No new replies allowed.