這似乎應該是一個基本的C++過程,但我不熟悉數據輸出。將CRC數據寫入.txt文件
當我打印數據而不輸出到文本文件時,我得到正確的值。
example: 00150017000 181
當打印到一個文本文件,這就是我得到:
11161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116111611161116
這裏是我的代碼:
ofstream myfile;
myfile.open("C:\\CRC.txt");
for (i = 0; i < 200; i++, id++)
{
myfile << sprintf(idstring, "%011d", id);
myfile << printf("%s %03d\n", idstring, computeCrc(idstring));
}
myfile.close();
其他一切工作正常,我知道是產生CRC正確。只需要獲得正確的輸出。
我能夠通過在調試屬性命令參數中添加「> CRC.txt」將控制檯屏幕輸出到文本文件,但我只是想知道如何將ofstream方法合併到此文件中。
在此先感謝。
@rozina哎呦看起來是:int_cdecl – terbubbs
我會刪除for循環,並開始調試運行在一個固定的數字。還有一個問題,爲什麼你將sprintf的結果保存到文件中? – rozina
說實話,不確定。使用源代碼我沒有寫,並試圖輸出它是我所做的一切。 @rozina – terbubbs