我已經創建了一個數組,但現在它的大小需要由文件中的行數決定,直到我使用for循環來放置數組元素在另一個文件中,我得到錯誤「_Pnext是0xCCCCCCD0」,爲什麼?如果我把一個數,即30在for循環,而不是NUMBER_OF_LINES,其優良工程動態數組大小與文件中行數的差異
int number_of_lines=0;
std::string line2;
std::ifstream myfile("Input_files\\Pronunciations.txt");
while (std::getline(myfile, line2))
{
++number_of_lines;
}
string *hexsource = new string[number_of_lines];
for (int o = 0; o <number_of_lines; ++o)
{
file2 >> name[o] >> ipaname[o] >> anyway[o];
}
使用'std :: vector'。不要'新的std :: string',它是一個值類型,就這樣使用它。 –
StoryTeller
'o <++ number_of_lines'似乎是可疑的。 – Jarod42
'hexsource'未使用,我們沒有聲明'file2','name','ipaname'和'anyway'。 – Jarod42