Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c+的不规则行为+;代码 我写了C++代码,好像没什么错。我使用Code::Blocks作为IDE,它没有给我任何警告或错误,但当我运行它时,它会给我一个框,表明我的exe文件没有响应_C++ - Fatal编程技术网

c+的不规则行为+;代码 我写了C++代码,好像没什么错。我使用Code::Blocks作为IDE,它没有给我任何警告或错误,但当我运行它时,它会给我一个框,表明我的exe文件没有响应

c+的不规则行为+;代码 我写了C++代码,好像没什么错。我使用Code::Blocks作为IDE,它没有给我任何警告或错误,但当我运行它时,它会给我一个框,表明我的exe文件没有响应,c++,C++,我的代码如下: 头文件: // DVD_App.h - Header File #include <string> #include <map> using namespace std; enum Status {ACTIVE, INACTIVE}; class Customer { private: string id; string name; string address; Status

我的代码如下:

头文件:

// DVD_App.h - Header File

#include <string>
#include <map>

using namespace std;

enum Status {ACTIVE, INACTIVE};

class Customer {
    private:
        string id;
        string name;
        string address;
        Status status;

    public:
        Customer (const string&, const string&, const Status);
        string &getId () { return id; }
};

class CustomerDB {
    private:
        static map<string, int> idList;

    public:
        static void addNewToIdList (const string &threeLetterOfName) {
            idList.insert(pair<string, int>(threeLetterOfName, 0));
        }

        static bool doesThreeLettersOfNameExist (const string &threeLetterOfName) {
            map<string, int>::iterator i = idList.find(threeLetterOfName);
            if ((i->first).compare(threeLetterOfName) != 0)
                return false;
            return true;
        }

        static int nextNumber (const string &threeLetterOfName) {
            map<string, int>::iterator i = idList.find(threeLetterOfName);
            ++(i->second);
            return i->second;
        }
};
//DVD\u App.h-头文件
#包括
#包括
使用名称空间std;
枚举状态{ACTIVE,INACTIVE};
类客户{
私人:
字符串id;
字符串名;
字符串地址;
地位;
公众:
客户(常量字符串和、常量字符串和、常量状态);
string&getId(){return id;}
};
类CustomerDB{
私人:
静态映射空闲列表;
公众:
静态void addNewToIdList(常量字符串和三个字母的名称){
idList.insert(一对(三个字母的名称,0));
}
静态bool不存在三个eletterSofName(常量字符串和三个LetterOfName){
迭代器i=idList.find(三个字母的名称);
如果((i->first).compare(三个字母的名称)!=0)
返回false;
返回true;
}
静态整数下一个数字(常量字符串和三个字母的名称){
迭代器i=idList.find(三个字母的名称);
++(一)第二;
返回i->second;
}
};
源代码:

// DVD_App.cpp - C++ Source Code

#include <iostream>
#include <string>
#include "DVD_App.h"

using namespace std;

map<string, int> CustomerDB::idList;

Customer::Customer (const string &cName, const string &cAddress, const Status cStatus) : name(cName), address(cAddress), status(cStatus) {
    string threeLetters = name.substr(0, 3);
    if (CustomerDB::doesThreeLettersOfNameExist(threeLetters))
        threeLetters += "" + CustomerDB::nextNumber(threeLetters);
    else {
        CustomerDB::addNewToIdList(threeLetters);
        threeLetters += "0";
    }
}

int main () {
    Customer k ("khaled", "beirut", ACTIVE);
    cout << k.getId() << endl;

    return 0;
}
<代码> /DVDApp.CPP-C++源代码 #包括 #包括 #包括“DVD_App.h” 使用名称空间std; 映射CustomerDB::idList; 客户::客户(常量字符串和cName、常量字符串和cAddress、常量状态cStatus):名称(cName)、地址(cAddress)、状态(cStatus){ 字符串三个字母=name.substr(0,3); if(CustomerDB::doesthrelettersofNameExist(三个字母)) 三个字母+=“”+CustomerDB::下一个数字(三个字母); 否则{ CustomerDB::addNewToIdList(三个字母); 三个字母+=“0”; } } int main(){ 客户k(“哈立德”,“贝鲁特”,活动);
cout您的
idList
最初是空的,因此当您调用
doesthreeltersofnameExist
时,
find()
返回的迭代器
i
将是
end()
迭代器,您可能无法取消引用。

如果
i==idList.end(),您应该签入函数doesthreettersofnameExist如果发生这种情况,则不能检查<代码>((i>第一)。比较(Stuple TyrOfNo.!)=0)<代码>。顺便说一下,在第一次迭代中发生的情况。也将此添加到NeXToT。< /P> LOL.<代码> >我写了一个C++代码,没有任何错误。< /代码>如果你出错,会发生什么?调试它吗?它进入主()吗?有吗?@Component10:lolatypo@Martin如何调试它,我是C++新手,我不知道该怎么做so@alzen92在linux上使用gdb/cgdb(也在使用cygwin的windows上)或在windows上使用visual studio调试器。还有其他选项,但这些是我通常使用的选项。