정렬되지 않은 map.There를 사용하여 전화 번호부를 C++로 만들려고합니다. cpp.sh에서는 완벽하게 실행되지만 Visual Studio에서는 완벽하지 않습니다. 그것으로? 도서관이나 진술이 누락되었거나 다른 것을 시도해야합니까?프로그램이 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");
}
이외의 값
은초기화
a
변수? 우리가 당신을 도울 수 있도록 좀 더 구체적이어야합니다. 가장 먼저해야 할 일은'system ("pause");' – setholopolus제거입니다. 시스템 ("일시 중지")이 없으면 검은 색 화면이 나타나지 않고 시스템 ("일시 중지")을 포함하면 검은 색 화면이 나타나지만 프로그램을 실행하지 않습니다. – usama97
그것은 내 시스템에서 작동했지만 Visual Studio가 없습니다. Visual Studio를 사용하는 방법과 무언가가 있어야합니다. – Eljay