Aillyn Aillyn - 1 year ago 68
C++ Question

Creating a set<char> in C++

I am coding this thing and it would be helpful to have a

static const set<char>
containing some elements that won't change.

class MyClass {
static const set<char> mySet = ??

How can I do this? It would be nice if you could create them from a string, like
, but I can't get the syntax to work.

Answer Source

Something like this will work just fine:

// my_class.h
class MyClass
  static const std::set<char> mySet;

// my_class.cpp
const char *tmp = "ABCDEFGHI";
const std::set<char> MyClass::mySet(tmp,tmp+strlen(tmp));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download