求助:vs2008编译boost程序出错!!!急!

syc0616 2008-11-08 01:37:13
#include "stdafx.h"
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
#include <windows.h>
using namespace std;
using namespace boost;
regex expression("^select (\d{1,3}\.){3}\d{1,3} from (\d{1,3}\.){3}\d{1,3} ");

int _tmain(int argc, _TCHAR* argv[])
{
std::string in;
cmatch what
int v1=2;
cout << "enter test string" << endl;
getline(cin,in);
if(regex_match(in.c_str(), what, expression))
{
for(int i=0;i<what.size();i++)
cout<<"str :"<<what[i].str()<<endl;
cin>>v1;
}

else

{
cout<<"Error Input"<<endl;
}
return 0;
}

警告: warning C4129: “d”: 不可识别的字符转义序列。
顺便问下我是想用正则表达式提取IP,这个程序有问题吗? 谢谢大家了。
...全文
159 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
syc0616 2008-11-08
  • 打赏
  • 举报
回复
太谢谢了,警告没有了。
对不起,我和的问个愚蠢问题,一个字符串中提去IP,该怎么些正则表达式呢?
比如:“源地址:172.16.0.98 源端口:50”
是不是 regex expression(" (\d{1,3}\.){3}\d{1,3}");
int _tmain(int argc, _TCHAR* argv[])
{
std::string in= "源地址:172.16.0.98 源端口:50";
cmatch what

if(regex_match(in.c_str(), what, expression))
{
for(int i=0;i <what.size();i++)
cout < <"str :" < <what[i].str() < <endl;

}
这样可以吗?谢谢。
liumingrong 2008-11-08
  • 打赏
  • 举报
回复
2)不需要
[Quote=引用 5 楼 syc0616 的回复:]
对了,还想问个问题。在VS2008
“Tools” -> “Options” ->
1) 在”Include files” 中添加boost根目录的路径,
2) 在”Source files” 中添加boost根目录的路径,
3) 在”Library files” 中添加刚才创建包含*.lib,*.dll文件的目录的路径。

我没添加2)可以吗?我编译一个程序通过了。
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
#incl…
[/Quote]
syc0616 2008-11-08
  • 打赏
  • 举报
回复
对了,还想问个问题。在VS2008
“Tools” -> “Options” ->
1) 在”Include files” 中添加boost根目录的路径,
2) 在”Source files” 中添加boost根目录的路径,
3) 在”Library files” 中添加刚才创建包含*.lib,*.dll文件的目录的路径。

我没添加2)可以吗?我编译一个程序通过了。
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
#include <windows.h>
using namespace std;
using namespace boost;
regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)");
int main(int argc, char* argv[])
{
std::string in;
cmatch what;
cout << "enter test string" << endl;
getline(cin,in);
if(regex_match(in.c_str(), what, expression))
{
for(int i=0;i<what.size();i++)
cout<<"str :"<<what[i].str()<<endl;
Sleep(5000);
}
else
{
cout<<"Error Input"<<endl;
}
return 0;
}
liumingrong 2008-11-08
  • 打赏
  • 举报
回复
试试 \\d
太乙 2008-11-08
  • 打赏
  • 举报
回复
var re=/^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))$/ ; //匹配IP地址的正则表达式
syc0616 2008-11-08
  • 打赏
  • 举报
回复
那是什么啊?请指教啊。谢谢你了。我想匹配数字。
太乙 2008-11-08
  • 打赏
  • 举报
回复
up~~~不是\d吧~~~

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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