class calcBMI {
public:
string line;
string line2;
fstream search;
short loop = 0;
string weight[6];
string height[6];
int index[6] = { 1, 2, 3, 4, 5 };
int i;
void getWeight() {
search.open("name.txt"); //Opens the text file in which the user details are stored
if (search.is_open())
{
while (getline(search, line)) { //While the program searches for the lines in the text file
if (line.find("Current Weight(KG): ") != string::npos) { //If the string "Name" isnt the last word on the line
weight[loop] = line; //Assings the strings read from the text file to the array called weight
cout << index[loop] << ". " << weight[loop] << endl; //Outputs the index array which loops through the numbers in the array and outputs the weight variable which loops through the strings in the array
loop++; //Iterates the loop
}
}
}
}
void getHeight() {
if (search.is_open())
{
while (getline(search, line2)) { //While the program searches for the lines in the text file
if (line2.find("Height") != string::npos) { //If the string "Name" isnt the last word on the line
height[loop] = line2; //Assings the strings read from the text file to the array called weight
cout << index[loop] << ". " << height[loop] << endl; //Outputs the index array which loops through the numbers in the array and outputs the weight variable which loops through the strings in the array
loop++; //Iterates the loop
}
}
}
}
void calculateBMI() {
calcBMI a;
a.getWeight;
a.getHeight;
}
};
我使用一个具有函数的类,通过从txt文件中获取数据来计算用户的BMI。但是,我得到以下错误:‘calsionbmi::getHL.8’:非标准语法;使用‘&’来创建指向成员的指针
你需要()在.的末尾getWheight; 和 getHeight;
void calculateBMI()
{
calcBMI a;
a.getWeight();
a.getHeight();
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。