how to print/access the 1st element of the first set of the vector

This is a discussion on how to print/access the 1st element of the first set of the vector within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <vector> #include <set> using namespace std; void add123(vector<set<int> >& numbers); int main() { vector<set<int> > vector_set; ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    Lightbulb how to print/access the 1st element of the first set of the vector

    Code:
    #include <iostream>
    #include <vector>
    #include <set>
    using namespace std;
    void add123(vector<set<int> >& numbers);
    
    int main()
    {
            vector<set<int> > vector_set;
            add123(vector_set);
            //cout << vector_set[0]; //how to print/access the 1st element of the first set of the vector vector_set?
            return 0;
    }
    void add123(vector<set<int> >& numbers)
    {
            set<int> s;
            s.insert(123);
            numbers.push_back(s);
    }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,656
    vector_set[0] is the first set. Since the expression vector_set[0] is a set object, use set's interface to access elements of the set.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error with a pointer
    By xphoenix in forum C Programming
    Replies: 27
    Last Post: 07-05-2010, 08:18 AM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 10:38 AM
  3. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 01:56 PM
  5. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 07:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21