Greetings.
I'm currently doing a project on Traveling Salesman Problem. But I'm not asking for answers for the whole project. I just started my programming lessons so I hope can get some help from all of you.
About this project: Initially you have to read 2 input files, Input1.txt and Input2.txt. An example of the contents for these 2 input files are as follows:
Input1.txt:
0 1
0 7
1 0
1 2 and so on..
Input2.txt:(Showing location name, first 3 numbers are for longitude and the next 3 numbers for latitude. Units for longitude are deg, min, sec)
Africa 111 85 23 2 14 59.72
America 112 27 55 2 29 35.29
China 101 21 22.31 2 20 21.29 and so on.....
My problem right now is after I wrote the codes to read the first file as shown below, it always display "Can't Open Input File!" as its cout result. Can I know where is it gone wrong? Another question is since I'm using array to store all the data, is using pointer will be easier than using array? Thank you for your help
-----------------------------------------------------------------------------------------------
#include <cstdlib> //to use exit()
#include <iostream>
#include <fstream>
using namespace std;
const int ARRAY_SIZE = 100;
void getConnectionValue(int connection[ARRAY_SIZE], int connection1[ARRAY_SIZE]);
int main()
{
//Declaring array
int connection [ARRAY_SIZE];
int connection1 [ARRAY_SIZE];
getConnectionValue(connection, connection1);
return 0;
}
void getConnectionValue(int connection[ARRAY_SIZE], int connection1[ARRAY_SIZE])
{
//Declare stream and open the first .txt file
ifstream inStream;
inStream.open("Input1.txt");
if (inStream.fail())
{
cerr << "Can't open input file!\n" << endl;
exit(1);
}
int i=0;
while (!inStream.eof())
{
inStream >> connection[i] >> connection1[i];
cout << i+1 << "numbers " << connection[i] << "and "<< connection1[i] << "\n" << endl;
i++;
}
inStream.close();
}