2017-12-09 3 views
-2

정렬되지 않은 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"); 
} 
+0

이외의 값

초기화 a 변수? 우리가 당신을 도울 수 있도록 좀 더 구체적이어야합니다. 가장 먼저해야 할 일은'system ("pause");' – setholopolus

+0

제거입니다. 시스템 ("일시 중지")이 없으면 검은 색 화면이 나타나지 않고 시스템 ("일시 중지")을 포함하면 검은 색 화면이 나타나지만 프로그램을 실행하지 않습니다. – usama97

+0

그것은 내 시스템에서 작동했지만 Visual Studio가 없습니다. Visual Studio를 사용하는 방법과 무언가가 있어야합니다. – Eljay

답변

1

a 전역 변수이며, 기본값은 주요 기능이 while 루프에서 a != 0 false를 반환하고 작업 main 끝을 상태를 시작 따라서 때, 0 : 다음은 내 코드입니다. 오류가 무엇을 받고있다 0

+0

그래서 어떻게해야합니까? 도와주세요. 나는 메인 안에 "a"를 먼저 선언하지만 에러가 발생했습니다. – usama97

+0

은'a' 변수의 정의를 main 함수로 옮기고 값을 1로 설정합니다.'int main() {int a = 1; ...}' – rafix07

관련 문제