【发布时间】:2009-06-04 08:06:32
【问题描述】:
我一直在摸不着头脑,当我第一次使用 cmd 进入 project\debug 文件夹然后在那里运行程序时,这段代码运行良好。然后我添加了 if(in) 和 else 部分,然后它开始给我“调试断言失败”错误 mbstowcs.c
表达式 s != NULL
这对我来说没有任何意义..
我在cmd中使用了这个命令:prog.exe test.txt nuther.txt
这两个文件都存在于调试文件夹和主项目文件夹中..
有什么想法吗?
int main(int argc, char **argv)
{
parse_opts(argc, argv); //parse the arguments
return 0;
}
void parse_opts(int argc, char **argv)
{
string compl_out;
if( argc > 1 )
{
for( int i = 1; i < argc; i++ )
{
if( argv[i][0] = '>' )
{
ofstream out_file(argv[i+1]);
out_file << compl_out;
out_file.close();
break;
}
ifstream in(argv[i]);
string buff;
if(in)
{
while(getline( in, buff ))
cout << buff << endl;
compl_out.append(buff);
}
else
{
cout << "Can't open file: " << argv[i]
<< ", file doesn't exist or is locked in use. " << endl;
}
}
}
else
{
usage();
}
}
【问题讨论】: