我與我的構造的目標是:strcat的錯誤「未處理的異常。」
打開讀取到一個特定的字符串(「%%%%%」)之間存在的一切文件 放在一起每次讀取將行添加到變量(歷史記錄) 將最終變量添加到類型爲char(_stories) 的雙指針關閉該文件。
但是,當我使用strcat時,程序崩潰。但我不明白爲什麼,我試了好幾個小時沒有結果。 :/
下面是構造函數代碼:
Texthandler::Texthandler(string fileName, int number)
: _fileName(fileName), _number(number)
{
char* history = new char[50];
_stories = new char*[_number + 1]; // rows
for (int j = 0; j < _number + 1; j++)
{
_stories[j] = new char [50];
}
_readBuf = new char[10000];
ifstream file;
int controlIndex = 0, whileIndex = 0, charCounter = 0;
_storieIndex = 0;
file.open("Historier.txt"); // filename
while (file.getline(_readBuf, 10000))
{
// The "%%%%%" shouldnt be added to my variables
if (strcmp(_readBuf, "%%%%%") == 0)
{
controlIndex++;
if (controlIndex < 2)
{
continue;
}
}
if (controlIndex == 1)
{
// Concatenate every line (_readBuf) to a complete history
strcat(history, _readBuf);
whileIndex++;
}
if (controlIndex == 2)
{
strcpy(_stories[_storieIndex], history);
_storieIndex++;
controlIndex = 1;
whileIndex = 0;
// Reset history variable
history = new char[50];
}
}
file.close();
}
我也試過沒有結果字符串流..
編輯:忘了發佈錯誤消息: 「未處理的異常在0x6b6dd2e9(msvcr100d .dll)在Step3_1.exe中:0xC00000005:訪問衝突寫入位置0c20202d20。「 了一個名叫「strcat.asm」文件打開..
問候 羅伯特
謝謝你們!我通過你的回答解決了這個問題! :) – Cyrix
很高興有幫助。既然你是一個新用戶,我希望你不要介意,如果我指出你對[接受答案]的一些筆記(http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer -工作) – simonc