我想给用户指定一个文件的选项(这里是ground_truth_filename
)。如果他没有指定选项,我想对默认文件名做出假设。
但是,即使我像在主程序中那样初始化它,我也无法检查ground_truth_filename
是还是零。如果参数由用户传递,我将分配给该参数。但是检查给了我一个断言错误。NULL
0
ground_truth_filename
ground_truth_filename == 0
任何帮助将不胜感激。
int processFile(const char *filename,
YAML::Emitter &out_yaml,
char *ground_truth_filename)
{
std::cout << "Here" << std::endl;
if (ground_truth_filename == 0)
sprintf(ground_truth_filename,"%s.yaml",filename);
std::ifstream imgstrm(filename, std::ios::binary | std::ios::in);
if (imgstrm.bad() || !imgstrm.is_open())
{
fprintf(stderr, "Failed to open file: %s\n", filename);
return FILE_ERROR;
}
// get ground truth
std::ifstream ground_truth_stream(ground_truth_filename);
if (!ground_truth_stream.is_open())
{
fprintf(stderr, "Failed to open file: %s\n", ground_truth_filename);
return FILE_ERROR;
}
}
这是函数的调用方式。也许我应该初始化 ground_truth_filename = '\0'?
char *ground_truth_filename = 0;
for (int i = 1; i + 1 < argc; i += 2) {
if (!strcmp(argv[i], "--snapshot-markup")) {
ground_truth_filename = argv[i + 1];
markupFlag = true;
}
}
processFile(filename, out_yaml, ground_truth_filename)