DevC++中regex_replace的坑
#include<bits/stdc++.h> using namespace std; int main() { string str="abc111abc222"; regex reg("abc"); string solve=regex_replace(str,reg,""); cout<<solve<<endl; return 0; }
一、DevC++5.9.2 中
测试环境:
TDM-GCC 4.8.1
是否开启c++11选项:是,选择了-std=c++11
报错:
[Error] no matching function for call to 'regex_replace(std::string&, std::regex&, const char [1])'
用命令行测试了这个版本的g++版本是什么
D:\Dev-C++\DevC++\Dev-Cpp\MinGW64\bin>g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=d:/dev-c++/devc++/dev-cpp/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-4.8.1/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-2 --with-bugurl=http://tdm-gcc.tdragon.net/bugs Thread model: posix gcc version 4.8.1 (tdm64-2)
二、PAT上
测试环境:C++ (g++ 6.5.0)
正常输出:
111222
三、牛客上
测试环境:C++(clang++11)
正常输出:
111222
其他测试,牛客上测试
#include<bits/stdc++.h> using namespace std; int main() { string str="Abc111abc222"; regex reg("abc"); string solve=regex_replace(str,reg,""); cout<<solve<<endl; return 0; } Abc111222
#include<bits/stdc++.h> using namespace std; int main() { string str="Abc111abc222"; regex reg("abc",regex::icase);//忽略大小写,注意,一定要写成“regex::icase”,前面不可少 string solve=regex_replace(str,reg,""); cout<<solve<<endl; return 0; } 111222