c++ - 如何在 qt creator 和 msvc 中使用 boost 正则表达式

标签 c++ qt visual-c++ boost boost-regex

我的系统中已经安装了 VS 2010。 因此,当我下载 QT(我必须使用 QT,因为这就是项目要求所在的位置)时,我使用了 this link并安装了它。 它能够自动检测可视化 C++ 编译器并且工作正常。

现在我从 boost.org 下载了 boost 库,并在 visual studio 命令提示符下使用以下命令安装:-

> bootstrap.bat msvc
> 
> c:\boost_1_54_0>b2 install --prefix=c:/boostinst toolset=msvc-10.0
> variant=debug ,release link=static threading=multi

之后我打开qt creator并添加以下代码cpp文件

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

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}

并使用 ADD Library 添加库并生成以下 .pro 文件。

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += C:\boostinst\include\boost-1_54 #if i remove this line, then also the same error



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../boostinst/lib/ -llibboost_regex-vc100-mt-1_54
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../boostinst/lib/ -llibboost_regex-vc100-mt-1_54d
else:unix: LIBS += -L$$PWD/../../../boostinst/lib/ -llibboost_regex-vc100-mt-1_54

INCLUDEPATH += $$PWD/../../../boostinst/include
DEPENDPATH += $$PWD/../../../boostinst/include

当我尝试构建时,它抛出以下错误

C:\Users\xxx\newcp\main.cpp:24:错误:C1083:无法打开包含文件:“boost/regex.hpp”:没有这样的文件或目录

我是漏掉了什么还是做错了什么?请任何人尽快回复。

最佳答案

已解决:使用以下命令在 32 位操作系统 Win7 和 msvc-10.0 中构建 boost_154_00

>     cd C:\boost_1_54_0\tools\build\v2\engine
>     build.bat msvc
>
>     cd boost_1_54_0
>     
>     set PATH=%PATH%;C:\boost_1_54_0\tools\build\v2\engine\bin.ntx86
>     
>     bjam toolset=msvc-10.0

然后在QT中新建工程,粘贴到ma​​in.cpp

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

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::string line;
     boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

     while (std::cin)
     {
         std::getline(std::cin, line);
         boost::smatch matches;
         if (boost::regex_match(line, matches, pat))
             std::cout << matches[2] << std::endl;
     }
    return a.exec();
}

.pro中添加

INCLUDEPATH+=C:\boost_1_54_0
LIBS+=-LC:\boost_1_54_0\stage\lib\

遵循指示 here

然后在qt project->run->arguments中添加arguments

关于c++ - 如何在 qt creator 和 msvc 中使用 boost 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17721390/

相关文章:

c++ - 如何在 Eigen (C++) 中处理复数?

c++ - 做个圈子把别人推开?

c++ - 使用 QMathGL 连接信号和槽

c++ - 带有 std::shared_ptr 的 QVariant

visual-c++ - 如何在 MFC(VC++) 中获取应用程序当前路径?

c++ - 在 Linux 上工作,在 Windows 7 上崩溃

c++ - 错误 C2143 : syntax error : missing ';' before '' template <''

c++ - 是否可以在不子类化的情况下使用 QThread 实现轮询?

c++ - 调试异常,源信息丢失

c++ - 我的棒球程序应该可以运行,但我就是找不到为什么它不能运行的问题。查看程序