The line auto& f = std::use_facet<std::ctype<char>>(std::locale(""));causes an error. The f reference is an alias for the null object. This implementation seems to work for gcc C + 11 compilers and above, but it does not work on Microsoft compilers. So the correct implementation in Visual Studio 2013 and 2015 that I tested is as follows:
#include "stdafx.h"
#include <locale>
#include <iostream>
#include <iterator>
int main()
{
std::locale loc(std::locale(""));
auto& f = std::use_facet<std::ctype<char>>(loc);
char s1[] = " \t\t\n Test";
const char* p1 = f.scan_is(std::ctype_base::alpha, std::begin(s1), std::end(s1));
std::cout << "'" << p1 << "'\n";
char s2[] = "123456789abcd";
const char* p2 = f.scan_is(std::ctype_base::alpha, std::begin(s2), std::end(s2));
std::cout << "'" << p2 << "'\n";
}
source
share