我尝试创建一个函数来识别字符串中匹配的行。我的整个字符串保存在 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;
}
}
}
当我编译我的代码时,我收到了以下错误
“../ user_model_impl.cxx”,第234行:错误#2289:没有构造函数的实例 “std :: basic_istringstream&lt; _CharT,_Traits, _Allocator&gt; :: basic_istringstream [with _CharT = char, _Traits = std :: char_traits,_Allocator = std :: allocator]“ 匹配参数列表 参数类型是:(RWCString) istringstream streamAddtText(strStart);
我无法找到此错误的原因。
答案 0 :(得分:5)
发生错误是因为istringstream
constructor需要std::string
,而不是RWCString
。如果您希望这样做,则需要提供从RWCString
到std::string
的转化。