當我使用這段代碼時,我得到了上面的錯誤。
//Programming Assignment 1
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Function Prototypes[/span]。
void getname(ofstream);
//void Evaluate_holesterol(ofstream);.
/void Evaluate_BMI(ofstream);
//void Evaluate_bloodpressure(ofstream);
int main()
{
//Open output file
ofstream pfile。
pfile.open("Profile.txt") 。
getname(pfile)。
//Evaluate_holesterol(pfile);
//Evaluate_BMI(pfile);.
//Evaluate_bloodpressure(pfile);
//pfile.close();
system("pause")。
return 0;
}
//Function to get patient's name[/span].
void getname(ofstream &pfile)
{
字串名稱。
int age。
cout<<"病人的全名是什么(包括中間名)?"。
getline(cin, name)。
cout<<endl<<"病人的年齡是多少?"/span>。
cin>>年齡。
string line = "病人的姓名。"。
string ageline = "病人的年齡:"。
pfile<<line name<<endl;
pfile<<age<<endl;
}
我已經檢查了我的函式和引數,我沒有看到任何函式的引數可能與其他地方混淆。如果它是一個簡單的東西,而我只是沒有看到它,請提前道歉。
uj5u.com熱心網友回復:
正如cigien和Peter的評論已經指出的。宣告和getname()的定義有不匹配的引數。要解決這個問題,請修改這一行
void getname(ofstream)。
to
void getname(ofstream& )。
注意在ofstream之后的&。
此外,任何獲得ofstream作為引數的函式應該通過參考獲得(即作為ofstream&而不是僅僅作為ofstream),因為ofstream沒有復制建構式,任何試圖通過值傳遞ofstream的嘗試都會導致編譯錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/317257.html
標籤:
上一篇:HTTP請求GET/POST
