What is the difference between using sets and lists? A set is ordered and cannot contain duplicates? When I look up the syntax on cppreference.com, they basically have the same code written down for set and list examples (for examples under set they use list<chat> and no mention of set<char> - here)
Here is some simple code I have that I wanted to loop through all the items in a set and print them out. When I use the above code it works (using list) but this code is giving me compiler errors:
Code:
#include <iostream>
#include <set>
#include <list>
int main()
{
int myInts[] = {1, 2, 3, 4};
set<int> iSet(myInts, myInts+5); // line 8
set<int>::iterator theIterator; // line 10
for(theIterator = iSet.begin(); theIterator != iSet.end(); theIterator++)
{
cout << *theIterator << "\n";
}
system("Pause");
return 0;
}
Code:
8 setTest.cpp `set' undeclared (first use this function)
8 setTest.cpp expected primary-expression before "int"
8 setTest.cpp expected `;' before "int"
10setTest.cpp expected primary-expression before "int"
10 setTest.cpp expected `;' before "int"
11 setTest.cpp `theIterator' undeclared (first use this function)
11 setTest.cpp `iSet' undeclared (first use this function)