在c ++

时间:2018-04-14 19:43:45

标签: c++ file

这是我的代码

ofstream Team_txt("Team.txt", ios_base::app);
cout << "Please enter team name: ";
cin >> Team_Name;
cout << "Please enter team Id: ";
cin >> Team_ID;
cout << "Please enter Captain name: ";
cin >> Team_Captain;
cout << "Please enter Total_Score name: ";
cin >> Total_Score;
Team_txt << Name << ' ' << Team_ID << ' ' << Team_Captain << ' ' << Total_Score << endl;
Team_txt.close();

我希望看到

enter image description here

但我明白了:

enter image description here

在第二张图片中,每行前面有一个空格,顶部有一个空行

1 个答案:

答案 0 :(得分:2)

在这一行:

Team_txt << Name << ' ' << Team_ID << ' ' << Team_Captain << ' ' << Total_Score << endl;

名称未在您的代码中定义,请检查它可能需要Team_Name而不是name