C++11简单正则表达式不适用于gcc 4.9.1
C++11 simple regex not working with gcc 4.9.1
我写的简单regex有问题:
std::regex reg = std::regex("(.*)[a-zA-Z]+(.*)");
它在一个简单的程序中工作,比如
#include <regex>
#include <exception>
#include <iostream>
int main(int argc, char *argv[])
{
std::regex reg = std::regex("(.*)[a-zA-Z]+(.*)");
std::string s("string");
if(std::regex_match(s, reg)){
std::cout << "MATCH !" << std::endl;
}
return 0;
}
但我有一个文件,我想用这个正则表达式处理它,但它不起作用。文件内容:
313801.91 323277.59 861.89
313770.97 323272.13 868.89
Start
End
313793.19 323290.19 864.89
我的程序:完整的程序代码;输入文件
...
std::ifstream input;
std::string cell;
std::regex reg = std::regex("(.*)[a-zA-Z]+(.*)");
input.open("a.txt", std::ofstream::in);
while (std::getline(input, cell))
{
// reject the row if there is any text in it
if( std::regex_match(cell, reg) ){
// never hit!
continue;
}
}
...
当我想把它打印出来时,我得到了一个奇怪的结果:
cout << "_____"" << cell << ""____" << endl;
"____"Start
问题在于行尾。我保存了一个以CLRF行结尾的文件(可能是在Windows上)。
我更新了我的正则表达式,现在它工作:
std::regex reg("(.*)[a-zA-Z]+(.*)(rn|n|r)");
相关文章:
- 为什么我的 SFINAE 表达式不再适用于 GCC 8.2?
- 适用于 gcc 4.8 的任何正则表达式库
- 流输入运算符导致分段错误与 clang 但适用于 gcc
- -static-libstdc++ 适用于 g++ 但不适用于纯 gcc?
- enable_if的模板专用化在 Clang 中失败,适用于 GCC
- 函数指针数组的类模板参数推导适用于 clang,但不适用于 gcc
- 可变参数模板作为模板参数:演绎适用于 GCC,但不适用于 Clang
- -m32 选项不适用于 gcc,但适用于 g++
- 在哪里可以下载适用于 Windows 的 GCC 4.3.2 二进制文件
- gcc-fdiagnostics颜色是否适用于Windows
- 将 C++11 正则表达式与 gcc 4.8.2 一起使用时会出现奇怪的结果(但适用于 Boost 正则表达式)
- Netbeans 8.1(适用于 C/C++)找不到我的编译器(gcc-6.0.0 开发版本)
- 在 Linux 上使用 GCC 交叉编译适用于 Windows 的 Qt 应用程序
- 宏调用中的 #ifdef 适用于 GCC,但不适用于 MSVC
- 静态表生成适用于 GCC,但不适用于 clang;被叮当窃听
- 用于提升program_options的自定义验证器不适用于 GCC,适用于 MSVC
- 模板的类型定义包括char[][] - 适用于VS2008,但不适用于gcc
- 如何构建独立于编译器的C++库(适用于 Solaris Studio 和 gcc)
- GCC 奇怪的链接器错误.适用于Visual Studio 2010
- 模板专用化适用于 gcc,但不适用于 Visual Studio 10