-1

我不明白发生了什么事。我编译了几次程序,一切都很顺利。但是自从我插入#include <unordered_map>后,我收到了诸如“cout 上未声明的标识符...没有 getline 的重载函数实例”之类的错误。我正在使用 Visual Studio 10。另外,如果有人能告诉我如何正确初始化unordered_map,那就太好了。

#include "stdafx.h"
#include<string>
#include <iostream>
#include <sstream>
#include <unordered_map>

using namespace std;

unordered_map<string, dictionary * > Mymap;

int _tmain(int argc, _TCHAR* argv[])
{
    string option;
    string pass;
    int choice=0;

    unsigned char hash[20];
    char hex_str[41];

    while(choice!=4)
    {
        cout<< "Select an option:"<< endl;
        cout<<"1. Basic Hashing"<<endl;
        cout<<"2. Load Dictionary"<<endl;
        cout<<"3. Decrypt"<<endl;
        cout<<"4. Exit" <<endl;

        getline(cin,option);
        stringstream(option) >> choice;

        if(choice == 1)
        {
            cout<<"Please enter a sample password"<<endl;
            getline(cin,pass);
            const char * c= pass.c_str();
            sha1::calc(c,pass.length(), hash);
            sha1::toHexString(hash,hex_str);
            cout<<endl;
            cout<<"Hashed: "<< hex_str<<endl;
        }
        else if(choice ==2)
        {
            string answer;
            cout<<"Would you like to use the default dictionary file(d8.txt). Press y or n"<<endl;
            getline(cin,answer);
        }
    }
    return 0;
}
4

1 回答 1

1

请参阅这篇关于以及为什么不使用它的帖子。using namespace std下面的代码仍然无法编译,但只有关于sha1您可能在某处丢失的定义的错误。(我在上面添加了 struct defMymap只是为了减少错误)。

关于错误,通常 C++ 编译器会在遇到第一个错误时为您提供有意义的错误描述,但此后,事情可能会变得奇怪,因此您一次修复一个错误以开始弄清楚。

#include "stdafx.h"
#include <string>
#include <iostream>
#include <sstream>
#include <unordered_map>

typedef struct dictionary{ std::string word; char * hash; char *hex; } a_dictionary;
std::unordered_map<std::string, a_dictionary * > Mymap;

int _tmain(int argc, _TCHAR* argv[])
{
    std::string option;
    std::string pass;
    int choice=0;

    unsigned char hash[20];
    char hex_str[41];

    while(choice!=4)
    {
        std::cout<< "Select an option:"<< std::endl;
        std::cout<<"1. Basic Hashing"<<std::endl;
        std::cout<<"2. Load Dictionary"<<std::endl;
        std::cout<<"3. Decrypt"<<std::endl;
        std::cout<<"4. Exit" <<std::endl;

        getline(std::cin,option);
        std::stringstream(option) >> choice;

        if(choice == 1)
        {
            std::cout<<"Please enter a sample password"<<std::endl;
            getline(std::cin,pass);
            const char * c= pass.c_str();
            sha1::calc(c,pass.length(), hash);
            sha1::toHexstd::string(hash,hex_str);
            std::cout<<std::endl;
            std::cout<<"Hashed: "<< hex_str<<std::endl;
        }
        else if(choice ==2)
        {
            std::string answer;
            std::cout<<"Would you like to use the default dictionary file(d8.txt). Press y or n"<<std::endl;
            getline(std::cin,answer);
        }
    }
    return 0;
}
于 2013-02-26T14:19:06.977 回答