fopen(),string,c-str(),无法打开文件,源码如下。有劳各位大神看看
void mfcc(string AudioName)
{
FILE *sourcefile;
ofstream outfile1("yuanshi.txt");
//cout<<AudioName<<endl; 此时可以输出 yuanshi.txt
sourcefile=fopen(AudioName.c_str (),"rb");
if(sourcefile==NULL)
{
cout<<"Can't open yuanshi.txt"<<endl;
exit(0);
}
}
int main()
{
string strAu1="yuanshi.txt";
cout<<strAu1<<endl;
mfcc(strAu1);
return 1;
} fopen,string,c-str() 源代码
[解决办法]
ofstream outfile1("yuanshi.txt");
//cout<<AudioName<<endl; 此时可以输出 yuanshi.txt
sourcefile=fopen(AudioName.c_str (),"rb");
你已经用ofstream打开了,文件已经被锁定,没法再用fopen打开啊,要么你把outfile1关掉
[解决办法]
为啥又用fstream又用FILE
[解决办法]
void mfcc(string AudioName)
{
FILE *sourcefile;
ofstream outfile1("yuanshi.txt"); //这里已经打开流了
//cout<<AudioName<<endl; 此时可以输出 yuanshi.txt
sourcefile=fopen(AudioName.c_str (),"rb"); // 这里又打开? 想干啥?
if(sourcefile==NULL)
{
cout<<"Can't open yuanshi.txt"<<endl;
exit(0);
}
void mfcc(string AudioName)
{
{
ofstream outfile1("yuanshi.txt");
//cout<<AudioName<<endl; 此时可以输出 yuanshi.txt
//will be closed before exit this bloc
}
FILE * sourcefile= fopen(AudioName.c_str (),"rb");
if(sourcefile==NULL)
{
cout<<"Can't open yuanshi.txt"<<endl;
exit(0);
}
}