I am very new to C++ and am trying to create a vector of points in a 2d plane read from a textfile. To do this I first create a struct consisting of two values (x,y) called point. Then a vector of these points called vec. However I am unsure of how to populate the struct data when the textfile is in three columns! The first column is just an index for the points, the second column is the x data and the third is the y data. I don't know the size of vec so I try to use push_back()
Here is what I have so far.
int main(){
struct point{
std::vector<x> vec_x;
std::vector<y> vec_y;
};
std::vector<point> vec;
vec.reserve(1000);
push_back();
ifstream file;
file.open ("textfile.txt");
if (textfile.is_open()){
/* want to populate x with second column and y with third column */
}
else std::cout << "Unable to open file";
}
Where the comment is I have the following;
while( file >> x )
vec.push_back (x);
while( file >> y )
vec.push_back (y);
Apologies if this is very simple, but it isn't to me! Posted below is an example of the txt file with only 6 points.
0 131 842
1 4033 90
2 886 9013490
3 988534 8695
4 2125 10
5 4084 474
6 863 25
EDIT
while (file >> z >> x >> y){
struct point{
int x;
int y;
};
std::vector<point> vec;
vec.push_back (x);
vec.push_back (y);
}