我有一个名为&#34的配置文件; Example.CFG"其中提到了main函数的参数。当我在visual studio 2013中运行代码时,它运行成功,但配置文件不向main提供任何参数,每次执行else部分。通过谷歌搜索我知道原因。 / Configure仅适用于Linux。我的问题是如何通过传递配置文件并直接向main提供参数。我的代码如下(代码不是我的,但是从Github下载)
int main(int argc, void** argv) {
tricrf::MaxEnt *model;
vector<string> model_file, train_file, dev_file, test_file, output_file;
string initialize_method, estimation_method;
size_t max_iter, init_iter;
double l1_prior, l2_prior;
enum {MaxEnt = 0, CRF, TriCRF1, TriCRF2, TriCRF3} model_type;
bool train_mode = false, testing_mode = false;
bool confidence = false;
////////////////////////////////////////////////////////////////
/// Reading the configuration file
////////////////////////////////////////////////////////////////
char config_filename[128];
if (argc > 1) {
strcpy_s(config_filename, (char*)argv[1]);
}
else {
cout << MAX_HEADER;
cout << "[Usage] max config_file \n\n";
exit(1);
}
我的Configur文件包含以下条目:
# sample configuration file
model_type = TriCRF3
# {MaxEnt CRF TriCRF1 TriCRF2 TriCRF3}
mode = both
# {train test both}
train_file = example.data
test_file = example.data
model_file = example.model
cutoff = 1
# feature cutoff by count
true_label = first
# if 'first' is on, it reads first columns as true labels
outside_label = NONE
# it would be used for F1 calculation
binary_model = false
# currently, not support
estimation = LBFGS-L2
# {LBFGS-L1 LBFGS-L2}