pointstr.cpp

来自「a simple code for using pointer in data 」· C++ 代码 · 共 50 行

CPP
50
字号
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
main()
{ int k,in,out,sechnum,count;
  char name[500][25];
  char *ptr[500],*temp;
  fstream f;
//  ifstream  infile;
  //ofstream outfile;
 // clrscr();
  cout<<"how many names do tou want to list?";
  cin>>k;
  cout<<"input the list of names "<<endl;
  for(count=0;count<k;count++)
    {
   cout<<"enter name of number "<<count+1<<":";
   cin>>name[count][25];}
   //cin.get();//for read and dicard end of line char
   //if(!name[count][0])
  // break;
  //ptr[count++]=name[count];
  //}
  cout<<"enter the number of name for searching for";
  cin>>sechnum;
    /*for(out=0;out<count-1;out++)
   for(in=out+1;in<count;in++)
    if((strcmp(ptr[out],ptr[in]))>0){
     temp=ptr[in];
     ptr[in]=ptr[out];
     ptr[out]=temp;
   }cout<<"<<the sorted list is:>>"<<endl;
    for(out=0;out<k;out++){
     cout<<"name"<<out+1<<"is"<<ptr[out];
     cout<<endl;                }*/
   f.open("stdlist.dat",ios::in|ios::in|ios::app);
  for(out=0;out<k;out++){
    f.write(name[out],25);}
    f.seekg(sechnum,ios::beg);
    f.read(name[sechnum],25);
    //cout<<name<<endl;
    f.close();
    cout<<name<<endl;
    getch();
    return 0;
    }


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?