i'm 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;
}

hey basit 3
i tried u'r instruction
now it dispalyes "the file could not be opened!" when i compile it :(

This question has already been answered. Start a new discussion instead.