我所做的 :
#include <vector>
#include <regex>
using namespace std;
int main() {
vector<regex> regexes = { "[a-z]+", "[0-5]+" };
}
它给了我一堆错误:
In file included from c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/vector:63:0,
from c:\cpp\test.cpp:1:
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_construct.h: In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = std::basic_regex<char>; _Args = {const char&}]':
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_uninitialized.h:77:3: required from 'static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const char*; _ForwardIterator = std::basic_regex<char>*; bool _TrivialValueTypes = false]'
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_uninitialized.h:119:41: required from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const char*; _ForwardIterator = std::basic_regex<char>*]'
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_uninitialized.h:260:63: required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = const char*; _ForwardIterator = std::basic_regex<char>*; _Tp = std::basic_regex<char>]'
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_vector.h:1170:4: required from 'void std::vector<_Tp, _Alloc>::_M_range_initialize(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag) [with _ForwardIterator = const char*; _Tp = std::basic_regex<char>; _Alloc = std::allocator<std::basic_regex<char> >]'
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_vector.h:1148:4: required from 'void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_InputIterator, _InputIterator, std::__false_type) [with _InputIterator = const char*; _Tp = std::basic_regex<char>; _Alloc = std::allocator<std::basic_regex<char> >]'
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_vector.h:393:4: required from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = const char*; _Tp = std::basic_regex<char>; _Alloc = std::allocator<std::basic_regex<char> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::basic_regex<char> >]'
c:\cpp\test.cpp:5:48: required from here
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/stl_construct.h:77:7: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
In file included from c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/regex:62:0,
from c:\cpp\test.cpp:2:
c:\mingw\bin\../lib/gcc/i686-w64-mingw32/4.7.2/include/c++/bits/regex.h:402:7: error: initializing argument 1 of 'std::basic_regex<_Ch_type, _Rx_traits>::basic_regex(const _Ch_type*, std::basic_regex<_Ch_type, _Rx_traits>::flag_type) [with _Ch_type = char; _Rx_traits = std::regex_traits<char>; std::basic_regex<_Ch_type, _Rx_traits>::flag_type = unsigned int]' [-fpermissive]
但是以上述方式用字符串初始化一个向量是可以的。