I am trying to pass document name to open in fstream, it works with ofstream but not with fstream.
Example, this works fine...
void TestFunction (ofstream &test,char FileName []){
cout << "test !!!" << endl;
test.open(FileName);
test << "test test test" << endl;
test.close();
}
int main ()
{
ofstream database;
char FileName[100]="database.txt";
TestFunction(database, FileName);
getchar();
return 0;
}
Example 2, this doesn't create file...
void TestFunction (fstream &test,char FileName []){
cout << "test !!!" << endl;
test.open(FileName);
test << "test test test" << endl;
test.close();
}
int main ()
{
fstream database;
char FileName[100]="database.txt";
TestFunction(database, FileName);
getchar();
return 0;
}
Anyone have any suggestions what am I doing wrong?
EDIT After some more Googling I found answer to my question, should I delete my question now or? c++: ifstream open problem with passing a string for text file name