Cannot Reading File

Hi,
Last week, I bought shared hosting at asphostportal. Now, I have little problem. Could you help me please? I am having a problem in reading a file i tried my code in code blocks/eclipse c++/netbeans c++ and even visual studio c++ 2010
each time it exits with (-1) while i'm puting the file in the right place for reading i don't know where is the mistake can you please help me
here's the file that i'm trying to read Problem.dat_50_50_0
here's my code:

#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv) {
ifstream inFile;
inFile.open("Problem.dat_50_50_0");
if ( !inFile ) {
cout << "the file could not be opened!" << endl;
exit(-1);
}
string line;
int n, value;
vector<int> w;
inFile >> n;
for ( int i = 0; i < n; ++i)
if ( inFile >> value )
w.push_back(value);
vector<vector<int> > matrix(n , vector<int>(n));
vector<vector<int> > adj(n);
for (int i = 0; i < n; ++i) {
cout << w.at(i) << ", ";
}
cout << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
inFile >> value;
matrix.at(i).at(j) = value;
if (value == 1)
adj.at(i).push_back(j);
}
}
for (int i = 0; i < adj.size(); ++i) {
cout << "[" << i << "]: ";
for (int j = 0; j < adj.at(i).size(); ++j) {
cout << adj.at(i).at(j) << ",";
}
cout << endl;
}
return 0;
}
I believe the correct error checking syntax is
1
2
3
4
5
6
ifstream inFile;
if(!inFile.open("Problem.dat_50_50_0")
{
cout<<"the file could not be opened!"<<endl;
return -1;
}

See if it still says it couldn't be opened if you change it to that. And use code tags. Also, why the file type .dat_50_50_0 not just .dat?
Topic archived. No new replies allowed.