I need to insert set STL container to insert(int k) function

Dear Community ,I'm trying to insert a set STL container into insert(int k) function;but the Linux Compiler says me: "set-btrees.cpp:336:23: error: no match for ‘operator[]’ (operand types are ‘s’ and ‘int’)
t.insert(data[i]);"
This issue belogs to the follow code:

!) The set was created from file like this:

 
  data.insert(dato); //create set with unique values 


dato is int dato and data comes from typedef std::set< int > s ;

2) The problems is here


1
2
3
4
5
6

  for(int i=0;i<data.size();i++)
       {
         t.insert(data[i]);       
       }
       


t belogs to BTreeNode which has a friendly class called BTree . In Btree is defined void BTree::insert(int k) function and t.insert must receipt the data[i] values.

This is my questions.

Thanks by your help.

Regards

Christian
Last edited on
A std::set does not have an operator [].

Fortunately, C++11's ranged-for loop comes to the rescue here:

1
2
3
4
for (int n : data)
    {
        t.insert( n );
    }

You can use the Reference documentation to catch these kinds of things:
http://www.cplusplus.com/reference/set/set/

Hope this helps.
Topic archived. No new replies allowed.