Welcome to OMG boards community!
Community of friends where we talk about daily life, offtopic stuff, and what keeps us busy.

You are currently viewing our community forums as a guest user. Sign up or
Having an account grants you additional privileges, such as creating and participating in discussions.

(C++) Structs and Vectors

Discussion in 'The Geek District' started by Toby_offtopica, Nov 30, 2014.

  1. Toby_offtopica

    Toby_offtopica OMG Member

    Threads:
    92
    Messages:
    587
    Likes Received:
    0
    Trophy Points:
    75
    Has any one else here had trouble learning to use Structs + Vectors in C++? It may seem pretty simple, but it's hard to remember and think about. It's like an array, but an array with Characteristics from the struct. You also have to do something different with for loops, but I remembered that [​IMG]. I would use a class, but I haven't learned those yet. I tired to learn classes, but they were difficult for me. I'll try again sometime [​IMG]




    Code:
    
    
    struct person {
    
    
    int age;
    
    
    string name;
    
    
    };
    
    
    
    
    vector Human;
    
    
    
    
    for(vector::size_type i = 0; i < 5; i++)
    
    
    {
    
    
    Human.push_back(person()); // <--- THIS ADDS 5 PEOPLE 
    
    
    }
    
    
    
    
    
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice