I agree with what @Frank said.
But rather than use your own method I would use a one that is already implemented by the standard library.
An easy way to copy a file into a vector is:
ifstream inFile3("E:\\Programming Languages\\HelloC++\\Geodetic\\Coordinate.txt");
std::vector<float> coordinate(std::istream_iterator<float>(inFile3),
std::istream_iterator<float>());
Other things to think about:
Stop doing this:
using namespace std;
Yes all books use this. But it is bad practice in general. They have a good excuse in a book that they only have so much horizontal space to keep things readable.
In reality using it is dangerous and should be avoided (even for short programs, as doing it here becomes a bad habit and bad habits have a tendency to accidentally intruding on production code).
See:: Why is “using namespace std” considered bad practice?
Don't declare all your variables at the top of a function.
unsigned short int num1;
float num2, num3;
vector<unsigned short int>index;
vector<float>lenght;
vector<float>coordinate;
ifstream InFile1;
ifstream InFile2;
ifstream InFile3;
Declare variables as you need them at the point where you are about to use them. Note a lot of these object have constructors that run code. You don't want to run code for an object that is never used. So only declare them just before you use them (and then use a good constructor).
Also by declaring them close to the point of usage it is easy to quickly see there types (without having to scroll to the top of the function).
Be specific with error messages.
if (!InFile1 || !InFile2 || !InFile3){
cerr << "Sorry Couldn't Open The File\n.";
}
Which file failed to open?
Learn to use standard algorithms and iterators
for (size_t i = 0; i < coordinate.size(); i++) {
cout << coordinate[i]<<endl;
}
In C++ we normally use iterators to loop over a container:
for (std::vector<float>::const_iterator loop = coordinate.begin(); loop != coordinate.end(); ++i) {
std::cout << *loop << "\n";
}
In C++11 we added auto to remove long type declarations.
for (auto loop = coordinate.begin(); loop != coordinate.end(); ++i) {
std::cout << *loop << "\n";
}
In C++11 we also added lambda's to make std::for_each()
easy to use:
std::for_each(coordinate.begin(), coordinate.end(),
[](auto const& item){std::cout << item << "\n";});
In C++14 we added range based for loop:
for (auto const& item: coordinate.begin()) {
std::cout << item << "\n";
}
Prefer to use prefix increment
for (size_t i = 0; i < coordinate.size(); i++)
^^^
Usually it does not matter. But sometimes it does. If you get in the habbit of using prefix increment then you always use the optimal version of increment.
Prefer '\n' over std::endl
Don't use return 0 in main when it can never error.
return 0;