#include <iostream>
#include <string>
// Define the struct
struct Student {
int student_id;
std::string name_id;
};
int main() {
// Create an instance of the struct
Student student;
// Input data using cin
std::cout << "Enter Student ID: ";
std::cin >> student.student_id;
// Clear the input buffer before reading a string with spaces
std::cin.ignore();
std::cout << "Enter Student Name: ";
std::getline(std::cin, student.name_id);
std::cout << "\n--- Student Details ---\n";
// View the result using cout
std::cout << "ID: " << student.student_id << "\n";
std::cout << "Name: " << student.name_id << "\n";
return 0;
}

Tidak ada komentar:
Posting Komentar