Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- istream& operator>>(istream& is, Card& d)
- {
- std::map<std::string,Card::Rank> mr;
- std::map<std::string,Card::Suit> ms;
- mr[std::regex("/two/i")] = Card::TWO;
- mr[std::regex("/three/i")] = Card::THREE;
- mr[std::regex("/two/i")] = Card::FOUR;
- mr[std::regex("/two/i")] = Card::FIVE;
- mr[std::regex("/two/i")] = Card::SIX;
- mr[std::regex("/two/i")] = Card::SEVEN;
- mr[std::regex("/two/i")] = Card::EIGHT;
- mr[std::regex("/two/i")] = Card::NINE;
- mr[std::regex("/two/i")] = Card::TEN;
- mr[std::regex("/two/i")] = Card::JACK;
- mr[std::regex("/two/i")] = Card::QUEEN;
- mr[std::regex("/two/i")] = Card::KING;
- ms[std::regex("/clubs/i")] = Card::CLUBS;
- ms[std::regex("/diamonds/i")] = Card::DIAMONDS;
- ms[std::regex("/hearts/i")] = Card::HEARTS;
- ms[std::regex("/spades/i")] = Card::SPADES;
- string srank, ssuit;
- char c1;
- if (is >> srank >> c1 >> ssuit)
- {
- if (c1 == 'of')
- {
- Card::Rank rank = mr[srank];
- Card::Suit suit = ms[ssuit];
- d = Card(rank, suit);
- }
- else
- {
- is.clear(ios_base::failbit);
- }
- }
- return is;
- }
- error C2679: binary '[' : no operator found which takes a right-hand operand of type 'std::basic_regex<_Elem>' (or there is no acceptable conversion)
- with
- [
- _Elem=char
- ]
- c:program files (x86)microsoft visual studio 11.0vcincludemap(173): could be 'Card::Rank &std::map<_Kty,_Ty>::operator [](std::basic_string<_Elem,_Traits,_Alloc> &&)'
- with
- [
- _Kty=std::string,
- _Ty=Card::Rank,
- _Elem=char,
- _Traits=std::char_traits<char>,
- _Alloc=std::allocator<char>
- ]
- c:program files (x86)microsoft visual studio 11.0vcincludemap(190): or 'Card::Rank &std::map<_Kty,_Ty>::operator [](const std::basic_string<_Elem,_Traits,_Alloc> &)'
- with
- [
- _Kty=std::string,
- _Ty=Card::Rank,
- _Elem=char,
- _Traits=std::char_traits<char>,
- _Alloc=std::allocator<char>
- ]
- while trying to match the argument list '(std::map<_Kty,_Ty>, std::basic_regex<_Elem>)'
- with
- [
- _Kty=std::string,
- _Ty=Card::Rank
- ]
- and
- [
- _Elem=char
- ]
- etc.
- #include <cctype>
- static inline void stringToLower(std::string &s) {
- for (uint i = 0; i < s.size(); ++i) {
- s[i] = tolower(s[i]);
- }
- }
- istream& operator>>(istream& is, Card& d)
- {
- std::map<std::string,Card::Rank> mr;
- std::map<std::string,Card::Suit> ms;
- mr["two"] = Card::TWO;
- mr["three"] = Card::THREE;
- ...
- mr["king"] = Card::KING;
- ms["clubs"] = Card::CLUBS;
- ...
- string srank, ssuit, c1;
- if (is >> srank >> c1 >> ssuit)
- {
- stringToLower(c1);
- if (c1 == "of")
- {
- stringToLower(srank);
- stringToLower(ssuit);
- Card::Rank rank = mr[srank];
- Card::Suit suit = ms[ssuit];
- d = Card(rank, suit);
- }
- else
- {
- is.clear(ios_base::failbit);
- }
- }
- return is;
- }
- static std::map<std::string,Card::Rank> createmr() {
- std::map<std::string,Card::Rank> mr;
- mr["two"] = Card::TWO;
- mr["three"] = Card::THREE;
- ...
- mr["king"] = Card::KING;
- return mr;
- }
- static std::map<std::string,Card::Rank> createms() {
- std::map<std::string,Card::Rank> ms;
- ms["clubs"] = Card::CLUBS;
- ...
- return ms;
- }
- istream& operator>>(istream& is, Card& d)
- {
- static std::map<std::string,Card::Rank> mr = createmr(); // note `static` keyword
- static std::map<std::string,Card::Suit> ms = createms();
- ...
- }
- static std::map<std::string,Card::Rank> mr = createmr(); // note `static` keyword
- static std::map<std::string,Card::Suit> ms = createms();
- istream& operator>>(istream& is, Card& d)
- {
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement