首页 > 解决方案 > 在 cpp 中从 argc=1 更改为 3 时输出无效

问题描述

我有一个包含 2 个案例的程序。

if(argc == 1){
    bool finish= false;
    while (!finish){
        try{
            std::cout<<"Gcalc>";
            std::string line;
            std::getline(std::cin,line);
            if(line==""){
                finish= true;
                continue;
            }

if(argc == 3){

    std::ifstream input_file(argv[1]);
    std::vector<std::string> lines;
    std::string line;
    while (!(input_file.eof())&&std::getline(input_file, line))
    {
        lines.push_back(line);
    }
    input_file.close();
    std::ofstream out(argv[2]);
    /*if(!out.is_open()){
        throw CouldNotOpenFile();
    }*/
    std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    std::cout.rdbuf(out.rdbuf());
    bool finish= false;

    std::cout.rdbuf(coutbuf);
    out.close();

我的项目背后的所有逻辑都可以正常工作,唯一的问题是,当我std::cout使用上面的字符串时:Gcalc它仅在终端中有效,但是当我将其发送到我的项目的自动检查器(我是学生)时,它会识别为失败,gcam需要在每个命令之后出现的单词没有出现。有什么建议吗?

只是为了确保 - 逻辑工作正常,cout打印每件事情都很好,而不是gcalc.

标签: c++swigcppcheck

解决方案


推荐阅读