Visual C++ - 尝试调试一个简单的链接列表代码



我正在尝试练习我的C++,我想从创建一个简单的链接列表开始。我在Visual Studio中这样做,我很难尝试调试这个小程序。当我运行该程序时,我得到的只是:

'LinkList.exe' (Win32): Loaded 'C:WindowsSysWOW64ntdll.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:WindowsSysWOW64kernel32.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:WindowsSysWOW64KernelBase.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:WindowsSysWOW64msvcp120d.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:WindowsSysWOW64msvcr120d.dll'. Cannot find or open the PDB file.
The program '[6016] LinkList.exe' has exited with code 0 (0x0).

法典:

#pragma once
class Node
{
public:
    Node(int);
    int data;
    Node *next;
    ~Node();
};
#include "stdafx.h"
#include "Node.h"

Node::Node(int d)
{
    data = d;
    next = NULL;
}
Node::~Node()
{
}
#pragma once
#include "Node.h"
class LinkedList
{
    Node *head;
    Node *end;
public:
    LinkedList();
    void appendAtEnd(int);
    void deleteNode(int);
    void printList();
    ~LinkedList();
};
#include "stdafx.h"
#include "LinkedList.h"
#include <iostream>
using namespace std;
LinkedList::LinkedList()
{
    head = 0;
    end = head;
}
void LinkedList::appendAtEnd(int d){
    Node* newNode = new Node(d);
    if (head == 0){
        head = newNode;
        end = newNode;
    }
    else{
        end->next = newNode;
        end = end->next;
    }
}
void LinkedList::deleteNode( int d){
    Node *tmp = head;
    if (tmp == 0){
        cout << "List is empty!n";
    }
    while (tmp->next != 0){
        if (tmp->data == d){
            tmp = tmp->next;
        }
        tmp = tmp->next;
    }
}
void LinkedList::printList(){
    Node *tmp = head;
    if (tmp == 0){
        cout << "List is empty!n";
    }
    if (tmp->next == 0){
        cout << tmp->data << endl;
    }   
    while (tmp != 0){
        cout << tmp->data << endl;
        tmp = tmp->next;
    }

}
LinkedList::~LinkedList()
{
}
#include "stdafx.h"
#include "LinkedList.h"
int _tmain(int argc, _TCHAR* argv[])
{
    LinkedList list;
    list.appendAtEnd(1);
    list.appendAtEnd(2);
    list.printList();
}

列表应该在控制台中打印(而不是在调试输出窗口中),但控制台关闭得太快,因此您看不到它。没有代码可以等待用户的某些输入。在 main 函数的末尾添加类似以下内容:

int _tmain(int argc, _TCHAR* argv[])
{
    ...
    cout << "Press Enter...";
    cin.get();
}

相关内容

  • 没有找到相关文章

最新更新