vector array to store coordinates

i've been trying to store a coordinate in a vector array, and reading the coordinates from a .txt file.

there was no error, but the size of the vector is still 0 (i'm sure there was no value in the vector array)

here's my code:

#include <stdafx.h>
#include<iostream>
#include<fstream>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {

ifstream myReadFile;
myReadFile.open("input test.txt");

vector<double> xVal,yVal;
int vectorSize = (int)xVal.size();

double x,y;

while (!myReadFile.eof()) {


myReadFile>>x>>y;
xVal.push_back(x);
yVal.push_back(y);

}
cout<<vectorSize<<endl;

myReadFile.close();
return 0;

}


any guide from the experts?
When you set int vectorSize = (int)xVal.size(); it will get the current size of the vector.
After you inserted some elements, you should update the value of vectorSize or it would still be 0.

Use [code][/code] tags when posting code
You might be better off keeping your X and Y coordiates together in some kind of record. If you wanted to add a z coordinate, or if you wanted to change the type to long long, it would make it easier.

e.g.
1
2
3
4
5
6
7
8
struct Coordinate
{
    double x, y;

    Coordiate(double paramx, double paramy) : x(paramx), y(paramy) {}
};

std::vector<Coordinate> coords;


And you'd add them like this:
1
2
    myReadFile>>x>>y;
    coords.push_back(Coordinate(x, y));
Topic archived. No new replies allowed.