I got some troubles trying to execute following code:
#include <iostream>
#include <regex>
int main(int argc, char** argv) {
std::wstring buffer; // Buffer string for input
std::wregex integerRegex(L"^-?[0-9]+$"); // Regex for integers (123, -123, etc.)
while (true) {
std::wcout << L"Enter your value:\n";
std::wcin >> buffer; // Input string from keyboard to determinate is it integer or not
// Check if integer or not
if (regex_match(buffer, integerRegex)) {
std::wcout << L"Integer!\n";
} else {
std::wcout << L"Unknown :(\n";
}
}
return 0;
}
This code should output Integer!
if entered sequence is integer or Unknown :(
if not. But in some case I got false-positive results:
When I enter something like: -234а
, where а
is cyrillic character - the code above say's it's integer, but it's not. Other cyrillic characters are not making such troubles.
Compiler is TDM-GCC 5.1.0 Compiled with following flags:
-std=c++11 -w -Wall -Wextra -pedantic -Werror -pg -pipe
Can someone explain what is the root of problem and who's wrong?