Здравствуйте, vandi711, Вы писали:
V>Использую я g++.
пишут, что regexp на gcc unusable
http://stackoverflow.com/questions/14776605/c-11-regex-error
этот код у меня работает на VS
на gcc не взлетело
| | Скрытый текст |
| | #include <regex>
#include <iostream>
#include <sstream>
int AsInt(const std::string& s)
{
int r = 0;
std::istringstream p(s);
p >> r;
return r;
}
void Parse(const std::string& s)
{
std::regex r("^(\\s*[^\\s-]+) (\\d+)$");
std::smatch m;
if (!std::regex_match(s, m, r))
{
std::cout << "NO MATCH for string '" << s << "'" <<std::endl;
return;
}
std::cout << "parsed string '" << s << "'" << std::endl;
const std::string s1 = m[1].str();
const int id = AsInt(m[2].str());
std::cout << "s1 = '" << s1 << "', n = " << id << std::endl;
}
int main()
{
const char* source[] = {"root 1", " root/folder 5", " root/folder/example1000 10", " a b c d 4", "a b c"};
for(auto& i : source)
{
Parse(i);
}
return 0;
}
|
| | |
успехов