我想通过文档名称在fstream中打开,它适用于ofstream但不适用于fstream。fstream,ofstream,传递文档名称,C++
例子,这工作得很好...
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;
}
例2,这不会产生文件...
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;
}
任何人有任何建议,我究竟做错了什么?
编辑 后一些更多的谷歌搜索,我发现回答我的问题,我是否应该现在或删除我的问题吗? c++: ifstream open problem with passing a string for text file name
我不认为你的问题是文件没有创建发布代码 – P0W