Created
November 14, 2014 00:45
-
-
Save dgodfrey206/af594bb14f21eaa93345 to your computer and use it in GitHub Desktop.
Facet that ignores all alphabetical characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
class whitespace_fmt : public std::ctype<char> | |
{ | |
mask table[table_size]; | |
public: | |
whitespace_fmt(size_t refs = 0) | |
: std::ctype<char>(table, false, refs) | |
{ | |
for (auto c : "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ") | |
{ | |
table[static_cast<int>(c)] |= space; | |
} | |
} | |
}; | |
int main() | |
{ | |
std::stringstream ss("abcdef12345ghij"); | |
ss.imbue(std::locale(ss.getloc(), new whitespace_fmt)); | |
std::string str; | |
ss >> str; | |
std::cout << str << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment