Visual Studio 2017 C ++控制台无法输出所有内容

时间:2017-06-25 05:16:33

标签: c++ visual-studio-2017

我在YouTube上播放了一个关于哈希表的视频,在测试一些输出时,我意识到我的控制台正在跳过不少行。

所以我的哈希表最初大小为10.当我运行程序时,一切都正常显示。但当我将大小增加到20时,我的控制台会跳过前3个索引。我不知道问题出在我的代码或Visual Studio上,但我希望有人知道。

这是控制台输出的图片,大小为20:

image

尺寸10:

image

Hash::Hash() {
    for (int i = 0; i < tableSize; i++) {
        HashTable[i] = new item;
        HashTable[i]->name = "empty";
        HashTable[i]->drink = "empty";
        HashTable[i]->next = NULL;
    }
}

int Hash::hashFunction(std::string key) {
    int hash = 0;
    int index;

    for (int i = 0; i < key.length(); i++) {
        hash = (hash + (int)key[i]) * 17;
    }

    index = hash % tableSize;

    return index;
}

void Hash::addItem(std::string name, std::string drink) {
    int index = hashFunction(name);

    if (HashTable[index]->name == "empty") {
        HashTable[index]->name = name;
        HashTable[index]->drink = drink;
    }
    else {
        item* ptr = HashTable[index];
        item* n = new item;
        n->name = name;
        n->drink = drink;
        n->next = NULL;
        while (ptr->next != NULL) {
            ptr = ptr->next;
        }
        ptr->next = n;
    }
}

int Hash::numItemsIndex(int index){
    int count = 0;

    if (HashTable[index]->name == "empty")
        return count; //0
    else {
        count++;
        item* ptr = HashTable[index];
        while (ptr->next != NULL) {
            count++;
            ptr = ptr->next;
        }
    }
    return count;
}

void Hash::printTable(){
    int number;

    for (int i = 0; i < tableSize; i++) {
        number = numItemsIndex(i);
        cout << "-------------------------\n";
        cout << "Index = " << i << endl;
        cout << HashTable[i]->name << endl;
        cout << HashTable[i]->drink << endl;
        cout << "# of items = " << number << endl;
        cout << "-------------------------\n";
    }   
}

void Hash::printItemsInIndex(int index){
    item* Ptr = HashTable[index];

    if (Ptr->name == "empty")
        cout << "Index " << index << " is empty. \n";
    else {
        cout << "Index " << index << " contains the following items: \n";
        while (Ptr != NULL) {
            cout << "-------------------------\n";
            cout << Ptr->name << endl;
            cout << Ptr->drink << endl;
            cout << "-------------------------\n";
            Ptr = Ptr->next;
        }
    }

}


int main(int argc, char* argv[]) {
    Hash Hashy; //create of tablesize 10 and initialize
                // all with items -> empty, empty, NUll.

    Hashy.addItem("Paul", "Locha");
    Hashy.addItem("Kim", "Iced Mocha");
    Hashy.addItem("Emma", "Strawberry Smoothie");
    Hashy.addItem("Annie", "Hot Chocolate");
    Hashy.addItem("Sarah", "Passion Tea");
    Hashy.addItem("Pepper", "Caramel Mocha");
    Hashy.addItem("Mike", "Chai Tea");
    Hashy.addItem("Steve", "Apple Cider");
    Hashy.addItem("Bill", "Root Beer");
    Hashy.addItem("Marie", "Skinny Latte");
    Hashy.addItem("Susan", "Water");
    Hashy.addItem("Joe", "Green Tea");

    Hashy.printTable();
    //Hashy.printItemsInIndex(8);


    system("pause");
    return 0;
}

输出部分有一些内容,但我不知道它们的含义:

'LetsHash.exe' (Win32): Loaded 'C:\Users\Rohan Vidyarthi\Desktop\LetsHash\Debug\LetsHash.exe'. Symbols loaded.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\kernel32.dll'
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WRusr.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wininet.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleacc.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\urlmon.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secur32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
The thread 0xbc8 has exited with code 252968960 (0xf140000).
The thread 0x1700 has exited with code 0 (0x0).
The thread 0x19bc has exited with code 0 (0x0).
The thread 0x1b70 has exited with code 0 (0x0).
The program '[3484] LetsHash.exe' has exited with code 0 (0x0).

2 个答案:

答案 0 :(得分:0)

您的哈希函数不会为每个字符串生成唯一编号,因此某些索引将是重复的。如果打印出每个字符串的索引,可以看到这个:

Paul, 0 
Kim, 3
Emma, 6 
Annie, 7
Sarah, 1
Pepper, 2 
Mike, 2 
Steve, 9
Bill, 9
Marie, 0 
Susan, 6 
Joe, 8

哈希值需要更大的范围才能避免哈希冲突。 0..9的范围太小,几乎会与您当前的方法产生碰撞。

答案 1 :(得分:-3)

错误是由于您没有ntdll和所有其他符号文件。你可以做些什么来避免这个错误: - 你可以有多种选择。

下载微软提供的符号包。这将为所有系统库下载PDB。将其解压缩到&#34; c:\ symbolcache&#34; 将符号路径设置为SRVc:\ symbolcachehttp://msdl.microsoft.com/download/symbols。在这种情况下,这将把PDB文件下载到&#34; c:\ symbolcache&#34;如果没有。 然后你必须设置&#34; c:\ symbolcache&#34;作为您正在使用的任何崩溃转储分析工具的符号文件路径。

对于错误,您可以共享代码如何调用哈希。