Simply create an input file stream and read each value one at a time. Then convert each value as you encounter it to its numerical value (double).
If you have never used file streams, read:
http://cplusplus.com/doc/tutorial/files/
Below is a short example. It's up to you to handle the values, but here's how you would read them from your input file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
//Create input stream (handles formatted input by default)
std::ifstream input;
//Open your file
input.open("TextFile1.txt");
//Create string to hold text values
std::string str;
//Retrieve each value from the input stream until EOF reached
while (input >> str)
{
//... convert the text to a double-precision value...
//... add value to your container ...
}
//Close the input file
input.close();
//... rest of your program ...
|
By default, ifstreams will handle formatted text. This means that values separated by whitespace (spaces, tabs, newlines) are automatically considered separate values. The loop continues until the end of the file is reached, so you don't need to know the number of entries ahead of time. This example omits error checking.
If you need help with conversion from text to double-precision, look into the functions atof() and strtod() - I prefer the latter because you can do some error-checking using it.
Typically, programmers define our own container to handle 3d point or vector types. It's very simple. For example, you could define a struct:
1 2 3 4 5 6
|
typedef struct
{
double x;
double y;
double z;
} Point3D;
|
That's just one example out of the
many ways programmers handle 3d points. Use whatever suits you. Then you can store your point containers in an array. Since you don't know the number of elements ahead of time, look into using std::vector as your container:
http://cplusplus.com/reference/stl/vector/