假設std::stringstream
實際上包含什麼相當於字面"sigma=0\\nreset"
(長度= 14個字符),而不是"sigma=0\nreset"
(長度爲13個字符),你必須自行更換。這樣做是不是很困難的,無論是使用升壓轉換器的replace_all
(http://www.boost.org/doc/libs/1_53_0/doc/html/boost/algorithm/replace_all.html),或std::string::find
和std::string::replace
:
std::stringstream inStream;
inStream.str ("sigma=0\\nreset");
std::string content = inStream.str();
size_t index = content.find("\\n",0);
while(index != std::string::npos)
{
content.replace(index, 2, "\n");
index = content.find("\\n",index);
}
std::cout << content << '\n';
注意:你可能要考慮的情況下,當結束行系統其他東西比"\n"
如果std::stringstream
實際上包含"sigma=0\nreset"
,則請將複製/處理和寫入代碼發佈到文本文件。
用'「\\ n」'代替''\ n''不太可能,你能在讀完之後和寫入之前驗證字符串,並顯示你的輸出代碼嗎? – Useless 2013-04-11 15:12:17
xml文件是否包含一個換行符,或'\\'字符後跟一個'n'字符? – 2013-04-11 19:03:37