2013-09-24 29 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

相關問題