我正在尝试练习我的C ++,我想开始创建一个简单的链表。我在Visual Studio中这样做,并且我很难尝试调试这个小程序。当我运行程序时,我得到的是:
'LinkList.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Cannot find or open the PDB file.
'LinkList.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.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();
}
答案 0 :(得分:0)
列表应该在控制台中打印(而不是在调试输出窗口中),但是控制台关闭得太快,所以你不会看到它。没有代码可以等待用户的某些输入。在main
函数的末尾添加类似的内容:
int _tmain(int argc, _TCHAR* argv[])
{
...
cout << "Press Enter...";
cin.get();
}