I ran into the problem that gcc/g++ <= 4.8.X does not support RegEx (my first reaction was: WHAT?!).
After installing (Ubuntu 14.04 LTS) gcc-4.9 and g++-4.9 (which is supposed to support RegEx properly) I still the get same error:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
[1] 13608 abort (core dumped)
My CMakeLists.txt looks like this (working with Jetbrains CLion as IDE):
set(CMAKE_CXX_COMPILER g++-4.9)
cmake_minimum_required(VERSION 3.1)
project(project1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(project1 ${SOURCE_FILES})
My code looks like this:
#include <iostream>
#include <string>
#include <fstream>
#include <regex>
using namespace std;
(...)
char encryptChar(char cinput)
{
std::string s = std::string(1, cinput);
// simplified regex (also crashes)
std::regex e = std::regex("[a-z]");
if(std::regex_match(s, e))
{
// do some stuff, if string matches conditions
}
return cinput;
}
Compiler/Linker do not complain about anything. Program runs fine without the regex-lines.
> g++-4.9 --version
>>> g++-4.9 (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2
>>> Copyright (C) 2014 Free Software Foundation, Inc.
Aucun commentaire:
Enregistrer un commentaire