无法将StringStream.str()中的字符串值分配给String变量

时间:2014-05-23 06:18:51

标签: c++ string stringstream

我试图在下面的代码中比较2个字符串。 1是从boost :: filesystem :: path对象生成的。

bool CommLibManager::Initialize() {
    std::string cPath = xstr(CS_RUN_PREFIX);
    cPath += "/bin/";
    filesystem::path currPath = filesystem::path(cPath);
    filesystem::directory_iterator it(currPath);

    for (; it != filesystem::directory_iterator(); it++) {
        filesystem::path path = (*it).path();

        // avoid non shared libraries & non comm libs
        // @ubuntuPort: update compare() method call into std::string compatible boost::path::compare methods. 
        //if ((path.extension() != ".so") || ((path.filename().compare(0, 7, "libcscl")) != 0)) {


        std::stringstream strStream;
        std::string pathString;
        std::string filePattern = "libcscl";
        strStream << path.filename();

        //pathString = strStream.str();
        pathString.assign(strStream.str());

        std::cout << "File name: " << pathString << "Extension: " << path.extension() <<endl;
        if ((path.extension() != ".so") || (filePattern.compare(0, 7, pathString) != 0)) {   


        //if ((path.extension() != ".so") || (path.filename() != (filesystem::path)"libcscl")) {   
            //@ubuntuPort: Debug
            merr("@ubuntuPort: Debug");
            continue;
        }

        // Some code here.

        return true;
}

由于pathString.assign(strStream.str());行,我无法用上面的代码编译源代码。它给出了以下错误:

src/mgr.cpp: In member function ‘bool CommLibManager::Initialize()’:
src/mgr.cpp:41:37: error: expected unqualified-id before string constant

我无法理解原因,请帮忙。

0 个答案:

没有答案