Search
 
SCRIPT & CODE EXAMPLE
 

CPP

vector of structs c++

struct subject {
    string name;
    int marks;
    int credits;
};


int main() {
    vector<subject> sub;

    //Push back new subject created with default constructor.
    sub.push_back(subject());

    //Vector now has 1 element @ index 0, so modify it.
    sub[0].name = "english";

    //Add a new element if you want another:
    sub.push_back(subject());

    //Modify its name and marks.
    sub[1].name = "math";
    sub[1].marks = 90;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: length of 2d array c++ 
Cpp :: note++ 
Cpp :: number to binary string c++ 
Cpp :: c++ random number generator uniform distribution 
Cpp :: oncomponentbeginoverlap ue4 c++ 
Cpp :: how to print text on C++ 
Cpp :: arduino led code 
Cpp :: how to return 2d array from function c++ 
Cpp :: c++ triangle 
Cpp :: how to make crypto 
Cpp :: string to int arduino 
Cpp :: spicoli 
Cpp :: c++ round number up 
Cpp :: all of the stars lyrics 
Cpp :: c++ how to check whether a file exists? 
Cpp :: c++ rand 
Cpp :: typedef vector c++ 
Cpp :: remove last character from string c++ 
Cpp :: c++ length of char* 
Cpp :: c++ open all files in directory 
Cpp :: sort stl 
Cpp :: C++ Find the sum of first n Natural Numbers 
Cpp :: how to get size of char array in c++ 
Cpp :: c++ simple car game 
Cpp :: cpp init multidimensional vector 
Cpp :: prime factorisation of a number in c++ 
Cpp :: restting a queue stl 
Cpp :: C++ program that prints the prime numbers from 1 to 1000. 
Cpp :: std distance 
Cpp :: cpp vector2 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =