一种常见的方式是使用命令行参数来指定输入文件和输出文件的路径,例如:

./program input.txt output.txt

在程序中可以使用标准输入输出流来读取输入文件和输出结果,然后将结果写入指定的输出文件中,例如:

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[]) {
    if (argc != 3) {
        cerr << "Usage: " << argv[0] << " input_file output_file" << endl;
        return 1;
    }

    ifstream fin(argv[1]);
    if (!fin) {
        cerr << "Failed to open input file: " << argv[1] << endl;
        return 1;
    }

    ofstream fout(argv[2]);
    if (!fout) {
        cerr << "Failed to open output file: " << argv[2] << endl;
        return 1;
    }

    // 读取输入文件并处理数据,将结果写入输出文件
    // ...

    fin.close();
    fout.close();

    return 0;
}

这样就可以将用户程序的输出结果与测试数据对应起来,方便后续的评测和比较

国内输入输出重定向的方式将用户程序输出结果与测试数据对应

原文地址: https://www.cveoy.top/t/topic/fsTS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录