我在Visual Studio 2008 C++項目中定義了一個資源文件。問題是,使用LockResource方法獲取資源數據後,生成的char緩衝區包含Carriage返回和換行,其中原始數據僅包含Line提要。例如,如果原來的行包含:刪除回車char *(C++)
00 0A FC 80 00 00 27 10 00 0A FC 80 00 00 27 10
將所得的char *包含也回車返回(0D):
00 0D 0A FC 80 00 00 27 10 00 0D 0A FC 80 00 00
我嘗試下面的代碼來擺脫他們,但是這導致兩個回車和換行被刪除:
for (int i = 0; i < sz; ++i)
{
// Ignore carriage returns
if (data[i] == '\n') continue;
// ...
}
如何擺脫馬車迴歸但留下換行字符?
編輯:
爲了使其更具體。我寫的字符緩衝區到文件:
std::ofstream outputFile(fileName.c_str());
for (int i = 0; i < sz; ++i)
{
// Ignore carriage returns
// if (data[i] == '\r') continue; This leaves both CR and LF
// if (data[i] == 0x0D) continue; This leaves both CR and LF
if (data[i]) == '\n') continue; //This removes both CR and LF
outputFile << data[i];
}
發佈更多驗證碼。 – 2011-05-11 12:09:04
'\ r'將匹配回車符。 – verdesmarald 2011-05-11 12:09:50