我有一個txt格式的列表。我需要創建一個鏈表,並在其中放置文件每一行的每個數據。 我寫了一段代碼,但在運行後,Dos停止工作(「程序停止工作......」)。 誰能告訴我錯誤在哪裏?鏈接列表 - DOS錯誤
struct node
{
string data;
node *pas;
};
int main()
{
struct node *koke;
struct node *tmp;
koke = NULL;
string CH;
ifstream infile;
infile.open ("Liste_1.txt~");
tmp = new node;
tmp = koke;
int i=0;
while(i<rr) //rr is defined as a constant
{
getline(infile,CH);
tmp->data = CH;
tmp = tmp->pas;
i++;
}
感謝,
你確定你的文件是'Liste_1.txt〜'嗎? – herohuyongtao
是的,該文件是這樣命名的。當我對數組做同樣的事情時,一切都很好。這只是關於鏈接列表 – user3173029
爲了記錄,你可能沒有使用「Dos」,那是你的程序崩潰。如果你真的使用「Dos」,那麼,我爲你感到抱歉:) – SirDarius