简体   繁体   English

调试断言错误

[英]debug assertion error

I've been scratching my head for quite some time now, this code worked fine when I first used cmd to go inside the project\\debug folder then run the program there. 我已经摸索了很长时间,当我第一次使用cmd进入project \\ debug文件夹然后在其中运行程序时,此代码运行良好。 Then I added the if(in) and else part then it started giving me "debug assertion failed" errors mbstowcs.c 然后我添加了if(in),然后添加了其他部分,然后它开始给我“调试断言失败”错误mbstowcs.c

Expression s != NULL 表达式s!= NULL

It just doesn't make any sense to me.. 这对我来说毫无意义。

I used this command in cmd: prog.exe test.txt nuther.txt 我在cmd中使用了以下命令:prog.exe test.txt nuther.txt

Both files exists inside the debug folder and the main project folder.. 这两个文件都存在于debug文件夹和主项目文件夹中。

Any ideas? 有任何想法吗?

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

}

First impressions: 第一印象:

if( argv[i][0] = '>' )

should be: 应该:

if( argv[i][0] == '>' )

You are assigning instead of comparing. 您正在分配而不是进行比较。

I think you also might have intended the compl_out.append to be inside the while loop? 我认为您可能还打算将compl_out.append放在while循环内? As it is it won't append anying to that buffer: 因为它不会将任何内容附加到该缓冲区:

while(getline( in, buff ))
{
    cout << "buf" << buff << endl;
    compl_out.append(buff); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM