Reputation: 33
So, I want to know, how to do my code shorter:
set<char> t;
t.insert( 'a');
t.insert( 'A');
t.insert( 'o');
t.insert( 'O');
t.insert( 'y');
t.insert( 'Y');
t.insert( 'e');
t.insert( 'E');
t.insert( 'u');
t.insert( 'U');
t.insert( 'i');
t.insert( 'I');
cout<<t.count('O');
I'm sure, thet is another way will be shorter and more correctly. What is the easiest way do you know?
Upvotes: 1
Views: 2212
Reputation: 206607
set<char> t;
char v[] = {'a', 'o', 'y', 'e', 'u', 'i'};
for (int i = 0; i < 6; ++i )
{
t.insert(v[i]);
t.insert(v[i]+'A'-'a');
}
Upvotes: 0
Reputation: 47794
#include <algorithm>
//...
std::set<char> t;
std::string s= "aAoOyYeEuUiI";
std::copy( s.begin() , s.end(), std::inserter(t, t.begin() ) ) ;
Upvotes: 2
Reputation: 15488
With C++11 initialization:
std::set<char> t = {'a', <the rest>, 'I'};
Upvotes: 6