close

#include<iostream>
#include<cstdlib>
#include<fstream>
#include<cstring>
#include<cctype>
using namespace std;
int addone(fstream&);
int lookup(fstream&);

int main(void)
{
    int choice;

   fstream file("telbook.txt", ios::out|ios::out); 
   if(!file)
        cout<<"file open fail"<<endl;
   else 
   {
      do 
      {
          cout<<"function choice: (1)add new tel. (2)lookup tel (3)end :";
              cin>>choice;
             if(choice==1)
              addone(file);
          else if(choice==2)  
              lookup(file);
          else if(choice>3)
             cout<<"number is too large , try again"<<endl;
      }while(choice!=3);
       cout<<"goodbye "<<endl;
   }
   file.close();

system("pause");
return 0;
}

int addone(fstream &file1)
{
   char name[20];
    int num;
   cout<<"enter new name : ";
   cin.get(name,20);
   cout<<"enter tel number : ";
   cin>>num;
   file1<<name<<num<<endl;
   return 0;
}

arrow
arrow
    全站熱搜

    minsin 發表在 痞客邦 留言(0) 人氣()