C++ Program to print student details using a structure


In this program, You will learn how to print student details using structure in C++.


struct struct_name { 
     //variable declaration
};

Example: How to print student details using structure in C++.

#include<iostream>
using namespace std;

struct Student {
    int roll;
    char name[100];
    char university[100];
};

int main() {

    struct Student st;

    cout << "Enter your roll:";
    cin >> st.roll;
    cin.get();

    cout << "Enter your name:";
    cin.getline(st.name, 100);

    cout << "Enter university name:";
    cin.getline(st.university, 100);

    

    cout << "\nYour Roll is:" << st.roll;
    cout << "\nYour Name is:" << st.name;
    cout << "\nYour University is:" << st.university;

    return 0;
}

Output:

Enter your roll:101
Enter your name:Xiith.com
Enter university name:Xiith34

Your Roll is:101
Your Name is:Xiith.com
Your University is:Xiith34

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.