After calling std::setlocale(LC_ALL, "en_US.UTF-8") you can use std::iswalpha() to determine if something is a letter.
So the next program
#include <cwctype> #include <iostream> #include <string> int main() { std::setlocale(LC_ALL, "en_US.UTF-8"); std::wstring youreWelcome = L"Není zač."; for ( auto c : youreWelcome ) if ( std::iswalpha(c) ) std::wcout << c; std::wcout << std::endl; }
will print
Nenízač
to the console.
Note that std::setlocale() may not be thread safe on its own or in combination with some other functions that execute at the same time, for example std::iswalpha() . Therefore, it should only be used in single-threaded code, such as program start code. More specifically, you should not call std::setlocale() from FileHandler::removePunctuation() , but only std::iswalpha() if you need it.
source share