I can never get this to work correctly for me, and I'm looking to you guys for help now. This program is going to eventually calculate the betweenness centrality for nodes on a graph, but I'm trying to get the file I/O to work properly. Any ideas? Code in tags and attached. (The fileIn.cpp file is normally named fileIn.cxx, and not specifically included in the build, as that is taken care of within the headers)
Also: I have tried to choose the file path manually, and that didn't work either. I'm coding on Vista x64, though I don't see why that should be an issue.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "fileIn.h"
using namespace std;
int main()
{
int vertices;
vector<int> matrix;
string fileName=getFileName();
getData(vertices,matrix,fileName);
cout << vertices;
for(int i=0;i<(vertices*vertices);i++)
cout << matrix[i] << endl;
return 0;
} //main()
#ifndef fileIn
#define fileIn
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "fileIn.cxx"
using namespace std;
string getFileName();
void getData(int &vertices, vector<int> &matrix, const string& fileName);
#endif //fileIn
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "fileIn.h"
using namespace std;
string getFileName()
{
string fileName;
string directory;
size_t found;
string currentFile=__FILE__;
cout << "What is the name of the file to be analyzed? " << endl;
getline(cin, fileName);
found=currentFile.find_last_of("\\");
directory=currentFile.substr(0,found);
directory+="\\data\\";
directory+=fileName;
return directory;
}
void getData(int &vertices, vector<int> &matrix, const string& fileName)
{
int temp;
ifstream openFile;
openFile.open(fileName.c_str());
if(openFile.is_open())
{
openFile>>vertices;
while(!openFile.eof())
{
openFile>>temp;
matrix.push_back(temp);
}
openFile.close();
}
else
cout << "Unable to read file." << endl;
}