Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Last active September 28, 2015 09:03
Show Gist options
  • Save yohhoy/fa72e6cd4eb0b8071f64 to your computer and use it in GitHub Desktop.
Save yohhoy/fa72e6cd4eb0b8071f64 to your computer and use it in GitHub Desktop.
#include <locale>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
struct tsv_ctype : std::ctype<char> {
static const mask* make_table()
{
static std::vector<mask> lut(classic_table(), classic_table() + table_size);
lut[' '] &= ~space;
return &lut[0];
}
explicit tsv_ctype(std::size_t refs = 0)
: ctype(make_table(), false, refs) {}
};
int main ()
{
std::istringstream iss ("123\tHello world\t3.14");
int a;
std::string b;
float c;
iss.imbue(std::locale(iss.getloc(), new tsv_ctype));
iss >> std::skipws >> a >> b >> c;
std::cout << a << ":" << b << ":" << c << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment