如何使用一个存有file名字的string来打开那个file???

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:44:52
如何使用一个存有file名字的string来打开那个file???
比如
string filename=“test.txt";
这个时候 function call 应该怎么写?
还有别的答案么。。。。

说实话。。。一楼的答案不太看得懂。。。。

哎。。。郁闷死我了。。

#include < fstream >
#include <string>
#include <iostream>
using namespace std;

int main()
{
ifstream ifs( filename.c_str() );
if( ifs.fail() )
{return -1;}
....

ifs.close();

return 0;
}

#include <stdio.h>

void main()
{
char *filename = "test.txt";

FILE *fid;
fid = fopen ( filename, "w+");
fprintf(fid,"output to file");
fclose(fid);
}

==================================
(VC6调试通过)