Search
 
SCRIPT & CODE EXAMPLE
 

CPP

multiple objects in vector C++


#include <iostream>
#include <vector>

using namespace std;


class Student
{
public:

	string name;
	int age;

	Student(string name, int age)
	{
		this->name = name;
		this->age  = age;
	}
};

vector<Student> students;

int main()
{

	for (int i = 0; i < 10; i++)
	{
		Student student("name", i);
		students.push_back(student);
	}

	for (int j = 0; j < students.size(); j++)
	{
		cout << students[j].name << ":" << students[j].age << "
";
	}

}

Comment

PREVIOUS NEXT
Code Example
Cpp :: binary algebra cpp 
Cpp :: composition namespaces c++ 
Cpp :: How to clear keyboard buffer c++ 
Cpp :: catalan numbers c++ 
Cpp :: how to delete repeated element in stack c++ 
Cpp :: c++ void to avoid functions 
Cpp :: python pour débutant 
Cpp :: split the array there is an array val of n integers . A good subarray is defined as 
Cpp :: 1491. Average Salary Excluding the Minimum and Maximum Salary leetcode solution in c++ 
Cpp :: how to make a substring after certain position 
Cpp :: c++ code 2d block 
Cpp :: sprintf add two xeroes for a float number 
Cpp :: & before function arg in cpp 
Cpp :: C++ Battery Low 
Cpp :: wap in c++ to understand function template 
Cpp :: is there interfaces in c++ like 
Cpp :: QMetaObject_invokeMethod 
Cpp :: c++ rainbow text 
Cpp :: lcm recursive program in c++ 
Cpp :: c++ max function 
Cpp :: c++ how to get maximum value 
Cpp :: short hand if else in c++ 
Cpp :: string to wstring conversion c++ 
Cpp :: Come concatenare stringhe in c++ 
Cpp :: no match for ‘operator=’ (operand types are ‘std::basic_ostream’ and ‘int’) 
C :: unity change transparency script 
C :: golang loop through array 
C :: print boolean value in c 
C :: yourkill071 
C :: how to add two numbers in c programming 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =