boost::regexのサンプルプログラムを動かしてみよう

アクセスカウンタ -

目次


boost::regexのサンプルプログラムを動かしてみよう

※事前にMinGWと、boostをセットアップして置く必要があります。

ソースコード(test_regex.cxx)

/**
 * file:test_regex.cxx
 * @UTF-8N CR+LF
 * @UTF-8N
 */
#define STRICT

#include <iostream>
#include <string>
#include <boost/regex.hpp>

using std::cout;
using std::endl;
using std::string;
using boost::regex;
using boost::regex_match;

void test_regex()
{
    string str("Yanch's Programming Memo.");
    regex reg("Yanch.+Memo\\.");
    
    if (regex_match(str, reg))
    {
        cout << "===> Matched." << endl;
    }
    else
    {
        cout << "===> Not matched." << endl;
    }
}

int main(int argc, char *argv[])
{
    test_regex();
    
    return 0;
}


Makefile

CXX      = g++
CXXFLAGS = -finput-charset=UTF-8 -fexec-charset=UTF-8 -g3 -O0 -Wall
DEFS     = -DUNICODE -D_UNICODE
ECHO     = echo
INCLUDES = -I"$(BOOST_ROOT)/include"
LDFLAGS  = 
LIBS     = $(BOOST_ROOT)/lib/libboost_regex-mgw34-mt.lib
RM       = rm
TARGET   = test_regex.exe
OBJS     = test_regex.o

all : $(TARGET)

$(TARGET) : $(OBJS)
    $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)

test_regex.o : test_regex.cxx
    $(CXX) -o $@ -c $< $(CXXFLAGS) $(INCLUDES) $(DEFS)

clean :
    -$(RM) $(OBJS) $(TARGET)


実行結果


~test_regex_cxx>test_regex.exe
===> Matched.


サンプルプログラムのダウンロード

test_regex.lzh
最終更新:2008年09月10日 19:44
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。
添付ファイル