C++ Online Compiler
Example: Basic Student Structure Processing in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Basic Student Structure Processing #include <iostream> // For input/output operations #include <string> // For using std::string #include <vector> // For using std::vector (dynamic array) // Define the Student structure struct Student { int id; std::string name; double score; }; int main() { // Step 1: Declare a vector of Student objects // Using std::vector for dynamic sizing, more flexible than raw arrays. std::vector<Student> students; // Step 2: Populate student records // Let's add 3 student records for demonstration Student s1 = {101, "Alice", 85.5}; Student s2 = {102, "Bob", 78.0}; Student s3 = {103, "Charlie", 92.3}; students.push_back(s1); students.push_back(s2); students.push_back(s3); // Step 3: Display student records std::cout << "Student Records:" << std::endl; for (const Student& s : students) { // Range-based for loop for easy iteration std::cout << "ID: " << s.id << ", Name: " << s.name << ", Score: " << s.score << std::endl; } return 0; }
Output
Clear
ADVERTISEMENTS