2013-09-24 30 views
1

我试图创建一个函数来识别字符串中的匹配行。我的整个字符串保存在strStartstrToMatch包含搜索字符串。以下是我的代码CPP中没有构造函数错误的实例

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:没有构造 实例“标准:: basic_istringstream < _CharT,_Traits, _Allocator> :: basic_istringstream [与_CharT =炭, _Traits =标准:: char_traits,_Allocator =标准::分配器]” 参数列表 参数类型相匹配:(RWCString ) istrings tream streamAddtText(strStart);

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

+0

istringstream streamAddtText(strStart); istringstream在构造函数中将字符串作为参数,不确定什么是RWCString。 – Kunal

+0

RWCString是来自Rogue wave库的模板。我改变了代码来使用字符串,但我仍然得到相同的错误 – Mohan

+3

什么是你的代码中的字符串?也许它应该是'std :: string'? –

回答

5

发生错误是因为istringstreamconstructor需要std::string而不是RWCString。如果您想使用此功能,则需要提供从RWCStringstd::string的转换。

+0

我根据你的建议更改了代码,仍然面临同样的问题。我用新的代码和错误编辑了我的问题。谢谢 – Mohan

+0

@Mohan然后,在你编辑的代码中是什么'String'?一个用于'std :: string'的typedef?我猜想这仍然只是你的代码不能编译的原因。 –

+0

@makulik:是String创建问题。我将它改为std :: string。有效 – Mohan

相关问题