gpt4 book ai didi

C++ 错误 : expected primary-expression before '&' token

转载 作者:太空狗 更新时间:2023-10-29 23:43:54 25 4
gpt4 key购买 nike

我正在学习 C++,我有以下代码,它在第 39 行(fill_file() 调用)中给出了错误。我在网上搜索了解决方案,但找不到出现此错误的原因(在“&”标记之前应为主要表达式)。

#include <iostream>
#include <string>
#include <vector>
#include "../std_lib_facilities.h"
using namespace std;

struct Point {
double x;
double y;
};

void fill_file(vector<Point>& original_points) {
string outputfile="mydata.txt";
ofstream ost{outputfile};
if(!ost) error("Can't open outputfile ", outputfile);
for(int i=0;i<original_points.size();i++) {
ost << original_points[i].x << " " << original_points[i].y << endl;
}
}

int main() {
cout << "Please enter 3 points with a value: " << endl;
vector<Point> original_points;
Point p;
double x;
double y;
for(int i=0;i<3;i++) {
cin>>p.x;
cin>>p.y;
original_points.push_back(p);
}
cout << endl;
cout << endl << "Points: " << endl;
for(int i=0;i<original_points.size();i++) {
cout << original_points[i].x << " " << original_points[i].y << endl;
/* ost << original_points[i].x << " " << original_points[i].y << endl; */
}
cout << endl << endl;
fill_file(vector<Point>& original_points);
return 0;
}

我做错了什么?感谢您的帮助!!

最佳答案

您在调用 fill_file 函数时犯了一个错误:

fill_file(vector<Point>& original_points);

必须这样调用:

fill_file(original_points);

关于C++ 错误 : expected primary-expression before '&' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39311724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com