Again trouble :(

After not being able to find out what was is wrong in this program http://www.cplusplus.com/forum/beginner/161414/ I tried to write another one just to remember the language since I haven't worked with C++ for a long time.
But I faced again problems and can't find what is wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <set>
#include <string>
using namespace std;


class cls{
public:
	cls(char c) : c(c){}
private:
	char c;
};


int main(){

	set<cls> s{'a', 'c' , 'e'};

	cin.sync();
	cin.ignore();
	return 0;
}


I get all kind of strange errors in the xstddef file.
Last edited on
set<cls> s{'a', 'c' , 'e'};
this syntax is invalid

try it like this
set<cls> s = {'a', 'c' , 'e'}; // since c++11

Also: what are cin.sync(); and cin.ignore(); for?
Last edited on
The set need a way to compare two cls objects to decide in what order they should be stored. One way to do this is to overload operator< for the cls type.
Thanks Peter, that was the problem.
Gamer, this set<cls> s{'a', 'c' , 'e'}; is valid.
oh, thank you ! :D
Topic archived. No new replies allowed.