Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.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
该程序未在visual studio 2017中运行 我试图用无序的地图制作C++电话簿。代码中没有错误,它在CPP.SH中执行得很好,但在Visual Studio 2017中没有。我是否遗漏了任何库或任何语句,或者我是否应该尝试其他任何东西。 这是我的密码: #include <iostream> #include <string> #include <unordered_map> using namespace std; int a; class phoneBook { public: int y; string name; long int number; unordered_map <string, long int>::iterator it; unordered_map<string, long int> m; void enter() { cout << "Enter Name: "; cin.ignore(); getline(cin, name); cout << "Enter Phone Number: "; cin >> number; m.insert(make_pair(name, number)); return; } void search() { cout << "Enter Name: "; cin.ignore(); getline(cin, name); it = m.find(name); if (it != m.end()) { cout << "Name:- " << name << endl; cout << "Number:- " << it->second << endl; } else { cout << "Not Found"; } cout << endl; return; } }; int main() { phoneBook p; while (a != 0) { cout << "Enter 1 to add phone number" << endl; cout << "Enter 2 to search for phone number" << endl; cout << "Enter 0 to exit" << endl; cin >> a; if (a == 1) { p.enter(); } if (a == 0 || a == 0) { break; } else if (a == 2) { p.search(); } } return 0; system("pause"); } #包括 #包括 #包括 使用名称空间std; INTA; 班级电话簿{ 公众: int-y; 字符串名; 长整数; 无序映射::迭代器; 无序地图m; void enter() { 库特数; m、 插入(配对(名称、编号)); 返回; } 无效搜索() { cout_C++_Visual C++ - Fatal编程技术网

该程序未在visual studio 2017中运行 我试图用无序的地图制作C++电话簿。代码中没有错误,它在CPP.SH中执行得很好,但在Visual Studio 2017中没有。我是否遗漏了任何库或任何语句,或者我是否应该尝试其他任何东西。 这是我的密码: #include <iostream> #include <string> #include <unordered_map> using namespace std; int a; class phoneBook { public: int y; string name; long int number; unordered_map <string, long int>::iterator it; unordered_map<string, long int> m; void enter() { cout << "Enter Name: "; cin.ignore(); getline(cin, name); cout << "Enter Phone Number: "; cin >> number; m.insert(make_pair(name, number)); return; } void search() { cout << "Enter Name: "; cin.ignore(); getline(cin, name); it = m.find(name); if (it != m.end()) { cout << "Name:- " << name << endl; cout << "Number:- " << it->second << endl; } else { cout << "Not Found"; } cout << endl; return; } }; int main() { phoneBook p; while (a != 0) { cout << "Enter 1 to add phone number" << endl; cout << "Enter 2 to search for phone number" << endl; cout << "Enter 0 to exit" << endl; cin >> a; if (a == 1) { p.enter(); } if (a == 0 || a == 0) { break; } else if (a == 2) { p.search(); } } return 0; system("pause"); } #包括 #包括 #包括 使用名称空间std; INTA; 班级电话簿{ 公众: int-y; 字符串名; 长整数; 无序映射::迭代器; 无序地图m; void enter() { 库特数; m、 插入(配对(名称、编号)); 返回; } 无效搜索() { cout

该程序未在visual studio 2017中运行 我试图用无序的地图制作C++电话簿。代码中没有错误,它在CPP.SH中执行得很好,但在Visual Studio 2017中没有。我是否遗漏了任何库或任何语句,或者我是否应该尝试其他任何东西。 这是我的密码: #include <iostream> #include <string> #include <unordered_map> using namespace std; int a; class phoneBook { public: int y; string name; long int number; unordered_map <string, long int>::iterator it; unordered_map<string, long int> m; void enter() { cout << "Enter Name: "; cin.ignore(); getline(cin, name); cout << "Enter Phone Number: "; cin >> number; m.insert(make_pair(name, number)); return; } void search() { cout << "Enter Name: "; cin.ignore(); getline(cin, name); it = m.find(name); if (it != m.end()) { cout << "Name:- " << name << endl; cout << "Number:- " << it->second << endl; } else { cout << "Not Found"; } cout << endl; return; } }; int main() { phoneBook p; while (a != 0) { cout << "Enter 1 to add phone number" << endl; cout << "Enter 2 to search for phone number" << endl; cout << "Enter 0 to exit" << endl; cin >> a; if (a == 1) { p.enter(); } if (a == 0 || a == 0) { break; } else if (a == 2) { p.search(); } } return 0; system("pause"); } #包括 #包括 #包括 使用名称空间std; INTA; 班级电话簿{ 公众: int-y; 字符串名; 长整数; 无序映射::迭代器; 无序地图m; void enter() { 库特数; m、 插入(配对(名称、编号)); 返回; } 无效搜索() { cout,c++,visual-c++,C++,Visual C++,a是全局变量,其默认值为0,因此当while循环中的main函数启动条件时,a!=0返回false,并且main结束工作 使用非0的值初始化变量。您收到的错误是什么?您需要更具体一些,我们才能帮助您。我要做的第一件事是删除系统(“暂停”);无系统(“暂停”)黑屏不会出现,如果我包括系统(“暂停”)出现黑屏,但未执行程序。它在我的系统上工作,但我没有Visual Studio。一定与您使用Visual Studio的方式有关。它在cpp.sh中也工作,但在Visual Studio 2017或Vi

a
是全局变量,其默认值为0,因此当while循环中的main函数启动条件时,
a!=0
返回false,并且
main
结束工作


使用非0的值初始化
变量。

您收到的错误是什么?您需要更具体一些,我们才能帮助您。我要做的第一件事是删除
系统(“暂停”);
无系统(“暂停”)黑屏不会出现,如果我包括系统(“暂停”)出现黑屏,但未执行程序。它在我的系统上工作,但我没有Visual Studio。一定与您使用Visual Studio的方式有关。它在cpp.sh中也工作,但在Visual Studio 2017或Visual Studio 2012中不工作。那么我该怎么办?请帮助我。我首先声明“a”在main中,但它给出了一个错误。将
a
变量的定义移动到main函数中,并将其值设置为1。
int main(){int a=1;…}