The following is the code. It contains a struct student with int rno and string name as members. I use a loop to read the members of all student variables. But the program terminates as soon as i enter any letter. Also, the string entered is not displayed.
#include <iostream>
#include <string>
using namespace std;
int main() {
struct student {
int rno;
string name;
};
student s[4];
int i;
for( i = 0; i < 4; ++i) {
cin >> s[i].rno;
getline( cin, s[i].name );
}
string line = "";
for( i = 0; i < 80; ++i) line += '-';
cout << line << "ROLL\tNAME\n" << line << '\n';
for( i = 0; i < 4; ++i) {
cout << s[i].rno << '\t' << s[i].name << '\n';
}
}
Thank you.