Point argument (vector argument)
Hi,
I need to help with that word: "vector <point_t>& points". I don't know what I can write as an argument.
1 2 3 4
|
void print_points(vector <point_t>& points)
{
for (unsigned i = 0; i < points.size(); i++)
...
|
I think this is important for resolution.
1 2 3 4 5 6 7 8 9 10
|
struct point_t
{
int x, y;
point_t(int x = 0, int y = 0) : x(x), y(y) { }
};
vector <point_t> read_points()
{
vector <point_t> result;
...
|
Thanks for any help. :)
There are a few options to print the points:
The easiest is the second one with the range for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void print_points(vector <point_t>& points)
{
for (unsigned i = 0; i < points.size(); i++)
cout << points[i].x << "\t" << points[i].y << "\n";
}
void print_points2(vector <point_t>& points)
{
for (point_t p: points)
cout << p.x << "\t" << p.y << "\n";
}
void print_points3(vector <point_t>& points)
{
for (auto it = points.begin(); it != points.end(); ++it )
cout << (*it).x << "\t" << (*it).y << "\n";
}
|
But I can not enter the correct argument when calling a function. I don't know how call this function .. namely this term "points"
You just need to pass a vector of point_t like so:
1 2 3 4 5 6 7 8 9 10 11 12
|
int main()
{
vector<point_t> points =
{
{1, 1},
{2, 2},
{3, 3}
};
print_points(points);
print_points2(points);
print_points3(points);
}
|
Thank you very much. You are god of programming. :-)
Topic archived. No new replies allowed.