首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

fopen(),string,c-str(),没法打开文件,源码如下。有劳各位大神看看

2013-08-09 
fopen(),string,c-str(),无法打开文件,源码如下。有劳各位大神看看voidmfcc(string AudioName){FILE *sourc

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);
 }
 }


[解决办法]
引用:
关键是ofstream,fopen打开的是两个文件啊(一个是txt,一个是)。现在问题出在wav的读入。

那你再检查下文件名,我试过,不出错啊。

热点排行