【发布时间】:2013-10-06 10:19:19
【问题描述】:
我正在尝试传递文档名称以在 fstream 中打开,它适用于 ofstream 但不适用于 fstream。
例如,这很好用...
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
【问题讨论】:
-
我不认为你的问题是文件没有被发布的代码创建