Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ vector of class objects

#include <iostream>
#include <vector>
using namespace std;

class Site {
public:
    int i;
};

int main() {
    vector<Site> listofsites;
    Site *s1 = new Site;
    s1->i = 7;
    Site *s2 = new Site;
    s2->i = 9;
    listofsites.push_back(*s1);
    listofsites.push_back(*s2);
    vector<Site>::iterator it;
    for (it = listofsites.begin(); it != listofsites.end(); ++it) {
        cout << it->i;
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to know datatype of something in c++ 
Cpp :: cpp return array 
Cpp :: Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. 
Cpp :: cpp getter as const 
Cpp :: ++i and i++ 
Cpp :: remove element from vector c++ 
Cpp :: 2d vector in cpp 
Cpp :: c++ add two char together 
Cpp :: Find the biggest element in the array 
Cpp :: doubly linked list in cpp 
Cpp :: no template named vector in namespace std 
Cpp :: sort c++ 
Cpp :: c++ compile to exe 
Cpp :: after login redirect to dashboard in nuxt 
Cpp :: print hello world in c++ 
Cpp :: c++ #define 
Cpp :: c++ move semantics for `this` 
Cpp :: c for loop decrement 
Cpp :: toupper c++ 
Cpp :: Traversing a C++ Array 
Cpp :: prime number c++ 
Cpp :: Fisher–Yates shuffle Algorithm c++ 
Cpp :: operator precedence in cpp 
Cpp :: print Colored text in C++ 
Cpp :: z transfrom mathlab 
Cpp :: glfw error: the glfw library is not initialized 
Cpp :: c++ random int troll 
Cpp :: std::future 
Cpp :: len in cpp 
Cpp :: c++ preprocessor commands 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =