我 调试过l
#include <iostream>#include <string>
using namespace std;
int n=2;
string name[50],num[50];
void input_data();
void search(string);
int main()
{
string find_name;
cout<<"please input the number of class:"<<endl;
cin>>n;
input_data();
cout<<"please input name you want:";
cin>>find_name;
search(find_name);
return 0;
}
void input_data()
{
int i;
for(i=0;i<n;i++)
{
cout<<"please input name and number of student"<<i+1<<": ";
cin>>name[i]>>num[i];
}
}
void search(string x)
{
int i;
bool flag=false;
for(i=0;i<n;i++)
{
if(name[i]==x)
{ cout<<name[i]<<" has been found,his number is:"<<num[i]<<endl;
flag=true;
break;}
}
if(flag==false)
cout<<"can not find name"<<endl;
}[Discuz!]&Menu=yes" target="_blank">" border="0">