phonebook director
Apr 7, 2009 at 8:12pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <iostream>
#include <map>
#include <conio.h>
#include <string>
using namespace std;
int main()
{
map<string,unsigned long > phone_book; // empty ma
string name; // to hold names
unsigned long number; // to hold phone numbers
// unsigned pNumber[10][10]={0}; // an array to hold 10 digit phone number
while (name.compare("exit" )!=0) // if input is not exit continue loop
{
// if(name.compare("exit") !=0) // if string is not exit continue getting input
{
cout <<"Enter name: " ;
cin >> name; // using getline(cin, name) ==bug, cin >> == if space is enter ==bug(forever loop)
cout <<endl;
cout <<"enter phone number:" ;
cin >> number;
cout <<endl;;
phone_book.insert(pair<string, unsigned int >(name,number));
// phone_book[name]=number; //bug
// phone_book.insert(make_pair(name,number));/bug
}
}
for (map<string,unsigned long >::iterator iter = phone_book.begin(); iter != phone_book.end(); ++iter) // print the phone book
{
cout <<"name: " << " " <<iter->first <<endl; // print name
cout <<"phone:" << " " <<iter->second <<endl; // print number
}
getch();
return 0;
}
it runs and compiles but its very buggy, i commet were i think is the cause of bug, please debug this for me im a begginer
Apr 7, 2009 at 9:04pm UTC
Line 30 looks good to me...so does line 29. Watch for mismatching unsigned int and unsigned long for your pairs; line 28 doesn't look so good. Anyway, what's the problem?
Last edited on Apr 7, 2009 at 9:06pm UTC
Topic archived. No new replies allowed.