CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: vectors!

  1. #1
    Join Date
    Jan 2008
    Posts
    5

    vectors!

    how do we access vector indexes for instance 0,1,2,3 without using addresses and references?

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: vectors!

    Like this?
    Code:
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    
    int i = vec[1];
    - petter

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: vectors!

    Or maybe using an iterator??
    Code:
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    
    std::vector<int>::iterator it = vec.begin();
    
    int i = *it;
    int j = *(it++);
    Mike

  4. #4
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: vectors!

    Code:
    std::vector<int> vec;
    vec.push_back(1);
    vec.push_back(2);
    
    int i = vec.at(0);
    int j = vec.at(1);
    ?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured