i want to read to a 2d-array from a file, but for some reason the file is not opening (at least thats what the output says)
#include <fstream>
#include<string>
#include <iostream>
using namespace std;
int main(){
string filename;
cout<<"Please type the name of the file";
cin>>filename;
fstream file(filename.c_str());//same result with fstream file(filename.c_str(), fstream::in | fstream::out);
cout<<filename.c_str();
if (!file)
{
cout<<"file could not be opened"<<endl;
exit(1);
}
//...
}
every time, i get "fiile could not be opened". the file is in the same directory, with the same name. im using windows xp