Hello yat89,
Your program does not compile.
The first problem I see is on line 17 The prototype describes a function called "data", which I do not see the definition for, and on line 38 you have a variable "data" that looks like a 2D array or maybe you wanted a 2D vector. Not sure because I do not find a definition for this variable before it is used.
The next problem is line 38 is giving me an error, which translates to, Which "data" do you want to use? Your function "data", the variable "data" or the function "std::data()", which the compiler is trying to use?
Some tips:
When defining a constant variable it is generally accepted to use capital letters for the variable name.
Also try not to use a single letter for a variable name as it makes it hard to understand.
Lines 20 and 22 are better defined in "main". Try to avoid regular global variables like these as the whole file has access to them and it makes it harder to find where an unwanted change was made.
As for the variables "i" and "j" unless you have a need for them outside the for loop they are used in it is better to define them in the for loop(s) and keep them local to the for loop(s).
This creates a warning and will not keep the program from running
for(int i = 0; i < route.size(); i++)
. The problem here is that
route.size()
returns a"size_type" or "size_t", which is a type def for an "unsigned int", most of the time. And you are trying to compare an "unsigned int" to an "int". It works, but it is a type mismatch. Not a big problem, but something to keep in mind.
You open three files on lines 27 - 29, but how do you know that they are open? Over time I came up with this:
1 2 3 4 5 6 7 8 9 10
|
const std::string inFileName{ "myLoad.txt" };
std::ifstream inFile(inFileName);
if (!inFile)
{
std::cout << "\n File \"" << inFileName << "\" did not open" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3)); // <--- Needs header files chrono" and "thread".
return 1; //exit(1); // If not in "main".
}
|
Line 8. Is optional. if you do not need it you can delete it or put a comment on it.
For line 9 if the code is in "main" the return is best to use. If this code is in a function the "exit" will be needed. Since zero is considered a normal return value any number greater than zero is considered a problem. The number can be used outside the, (by whatever called the program) or yo can use this number to figure out where the problem is in your code.
You open three input files. Knowing the data contained in these files helps to understand what the program is doing and gives anyone trying to run your program the same data that you are using, so there is no guessing on how to create the files or using different data. The actual input files will help or a better explanation of what you have posted.
I will see what I can do with your program to get it to compile and try to run it.
Hope that helps,
Andy