C++中使用正则表达式

主要记录使用正则表达式编译时遇到的问题。

要使用正则表达式,需include<regex>,然后编译时报错:

g++    -c -o wgs2sgf.o wgs2sgf.cpp
In file included from d:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/regex:35:0,
                 from wgs2sgf.cpp:21:
d:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
make: *** [wgs2sgf.o] Error 1

makefile里面加上-std=c++0x选项后依然出错,仔细看才发现编译命令里面没出来-std=c++0x,原来是自己makefile写错了:

CC=g++
CCFLAGS=-std=c++0x -Wall
wgs2sgf:wgs2sgf.o
clean:
	rm -rf *.o

c++应该用CXX,改为:

CXX=g++
CXXFLAGS=-std=c++0x -Wall
wgs2sgf:wgs2sgf.o
clean:
	rm -rf *.o

依然报错:

cc   wgs2sgf.o   -o wgs2sgf
process_begin: CreateProcess(NULL, cc wgs2sgf.o -o wgs2sgf, ...) failed.
make (e=2): 系统找不到指定的文件。
make: *** [wgs2sgf] Error 2

看来还是得指定CC,makefile改为:

CC=g++
CXX=g++
CXXFLAGS=-std=c++0x -Wall
wgs2sgf:wgs2sgf.o
clean:
	rm -rf *.o

编译通过。

One thought on “C++中使用正则表达式

  1. Pingback: MinGW上使用正则表达式 | 知行近思

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注