求助c++高手

来源:百度知道 编辑:UC知道 时间:2024/06/22 17:20:18
{
string a,b,yonghuming;
cout<<"请输入学生本人信息:"<<endl;
string temp;
string yonghuming;
cin>>yonghuming;
cout<<"请输入学号:"<<endl;
cin>>a;
cout<<"请输入学号:"<<endl;
cin>>b;
temp="d:\\";
temp+=yonghuming;
temp+=".txt";
ofstream ofile(temp.c_str());
ofile<<"该学生的学号是:"<<a<<endl;
ofile<<"该学生的密码是:"<<b<<endl;
system("pause");
main();

错误是这样: error C2086: 'yonghuming' : redefinition

请问怎么改,错在哪里

{
string a,b,yonghuming;//第一次定义
cout<<"请输入学生本人信息:"<<endl;
string temp;
string yonghuming; //第二次定义,重复定义了
cin>>yonghuming;
cout<<"请输入学号:"<<endl;
cin>>a;
cout<<"请输入学号:"<<endl;
cin>>b;
temp="d:\\";
temp+=yonghuming;
temp+=".txt";
ofstream ofile(temp.c_str());
ofile<<"该学生的学号是:"<<a<<endl;
ofile<<"该学生的密码是:"<<b<<endl;
system("pause");
main();

“yonghuming”多定义了一次,把第五行删掉试试