Napisałem sobie program:
#include<regex>
#include<string>
#include<iostream>
int main()
{
try
{
std::regex reg("[0-9]+", std::regex_constants::extended);
std::string str;
std::cin>>str;
std::cout<<(std::regex_match(str, reg)?"match ":"no match ")<<str<<std::endl;
}
catch(const std::regex_error e)
{
std::cout<<e.what()<<std::endl;
}
return 0;
}
Powinien on wczytywać stringa i jeśli jest on liczbą wypisać match
, w przeciwnym wypadku no match
.
Jednak program wypisuje match
tylko wtedy, gdy na wejściu jest dokładnie jeden znak (nie ważne, czy jest to cyfra, litera, czy coś innego). Kiedy poda się więcej niż jeden znak dostaję no match
. Google mi nic nie pomógł (albo ja nie umiem szukać).
Mój kompilator: gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Co zrobić, aby to zadziałało?