【发布时间】:2016-09-03 22:04:53
【问题描述】:
我正在学习 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(original_points);
标签: c++