Google News
logo
C++ Program to Store and Display Information Using Structure
In the following example of C++ program to store and display information using structure :
Program :
#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;
}
Output :
Enter Name: Venkat
Enter Roll Number: 110124
Enter Marks: 79

Student Information:
Name: Venkat
Roll Number: 110124
Marks: 79
In this program, we define a structure student with three members name, roll_no, and marks. We then declare a variable s of type student.

We use 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.

Finally, we display the information using cout. Note that we use the dot operator (.) to access the members of the structure.