C++Builder 2010中使用boost 遇见问题。

saishow 2010-04-29 11:00:06
这是网上的一篇教程。我试着做了一次。但是结果编译不过。请大家指点指点。看错误在什么地方。

错误提示:
Checking project dependencies...
Compiling Project2.cbproj (Debug configuration)
[BCC32 Error] Unit2.cpp(20): E2451 Undefined symbol 'edt1'
Full parser context
Unit2.cpp(19): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] Unit2.cpp(21): E2451 Undefined symbol 'edt2'
Full parser context
Unit2.cpp(19): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] Unit2.cpp(21): E2285 Could not find a match for 'regex_match<iterator,charT,traits>(undefined,wregex)'
Full parser context
Unit2.cpp(19): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] Unit2.cpp(21): E2268 Call to undefined function 'regex_match'
Full parser context
Unit2.cpp(19): parsing: void _fastcall TForm2::Button1Click(TObject *)
Failed


代码:
//---------------------------------------------------------------------------

#include <boost/regex.hpp>
#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
boost::wregex regExp(edt1->Text.c_str());
if( regex_match(edt2->Text.c_str(), regExp ) )
{
ShowMessage(L"匹配成功!");
}
else
{
ShowMessage(L"匹配失败!");
}
}
//---------------------------------------------------------------------------




在C++Builder 2010中使用boost的正则表达式
在新发布的C++Builder 2010中,已经带了boost 1.39,

安装的时候,选上就可以了。
总的来说,C++ Builder 2010这点是做的不错的,省了我们为了使用boost,要自己下载,并长时间的编译所带来的痛苦。最重要的是,还不一定成功。

开始:菜单->File->New->VCL Forms Applications C++ Builder
这样,我们就有了一个带有Form的C++Builder工程。
然后在上面,拖上两个TEdit和TLabel控件和一个TButtom控件,并修改相应的属性,结果如下:

然后双击“匹配”这个按钮,就到产生单击事件,代码实现如下
void __fastcall TForm1::btn1Click(TObject *Sender)
{
boost::wregex regExp(edt2->Text.c_str());
if( regex_match(edt1->Text.c_str(), regExp ) )
{
ShowMessage(L"匹配成功!");
}
else
{
ShowMessage(L"匹配失败!");
}
}



记得,要在CPP的头部,加入正则表达式的头文件

#include <boost/regex.hpp>
然就可以编译运行了,结果如果下:

OK,完成。
在C++Builder下面,使用boost的正则表达式,非常的轻松!
由于boost的强大,使用C++Builder也非常的强大!
...全文
576 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lq48303847 2011-06-23
  • 打赏
  • 举报
回复
用不来 c++ builder 2010
saishow 2010-04-29
  • 打赏
  • 举报
回复
呵呵 edit 的i忘记了。
周药师 2010-04-29
  • 打赏
  • 举报
回复
遇见问题?
你在界面上放两个Edit 命名为edt1 和edt2 就行了


[BCC32 Error] Unit2.cpp(20): E2451 Undefined symbol 'edt1'
Full parser context
Unit2.cpp(19): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] Unit2.cpp(21): E2451 Undefined symbol 'edt2'

这是两个控件 Edit1 和Edit2 改的名字


[BCC32 Error] Unit2.cpp(21): E2285 Could not find a match for
[BCC32 Error] Unit2.cpp(21): E2268 Call to undefined function 'regex_match'
调用库函数 需要添加函数所在的头文件#include <boost/regex.hpp>

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧