CPP中没有构造函数错误的实例

Moh*_*han 1 c++

我试图创建一个函数来识别字符串中匹配的行.我的整个字符串保存在strStart中,strToMatch包含搜索字符串.以下是我的代码

void ExpertContextUser::removeMatchedString() {
        String line;
        String strStart="Testing\nReturns\nrelated\nresources";
        String strToMatch="Test";
        istringstream streamAddtText(strStart);
        while(std::getline(streamAddtText, line)) {
                cout << line << "Function" << endl;
                if(line.index(strToMatch) > 0) {
                        TraceMessage <<" Test Success" << endl;
                }
        }
}
Run Code Online (Sandbox Code Playgroud)

当我编译我的代码时,我得到以下错误

"../user_model_impl.cxx",第234行:错误#2289:没有构造函数的实例"std :: basic_istringstream <_CharT,_Traits,_Allocator> :: basic_istringstream [with _CharT = char,_Traits = std :: char_traits,_Allocator = std :: allocator]"匹配参数列表参数类型是:(RWCString)istringstream streamAddtText(strStart);

我无法找到此错误的原因.

Mar*_*ila 5

发生错误是因为istringstream 构造函数需要a std::string而不是a RWCString.您需要提供从转换RWCStringstd::string,如果你想这个工作.