#include <iostream>
using namespace std;
struct student {
string name;
int roll_no;
int marks;
};
int main() {
student s;
cout << "Enter Name: ";
getline(cin, s.name);
cout << "Enter Roll Number: ";
cin >> s.roll_no;
cout << "Enter Marks: ";
cin >> s.marks;
cout << endl << "Student Information:" << endl;
cout << "Name: " << s.name << endl;
cout << "Roll Number: " << s.roll_no << endl;
cout << "Marks: " << s.marks << endl;
return 0;
}
Enter Name: Venkat
Enter Roll Number: 110124
Enter Marks: 79
Student Information:
Name: Venkat
Roll Number: 110124
Marks: 79
name
, roll_no
, and marks
. We then declare a variable s
of type student
.getline()
to input the name of the student as it may contain spaces. We then use cin
to input the roll number and marks of the student.cout
. Note that we use the dot operator (.)
to access the members of the structure.