source/sample/transformer/Config.cpp
int NMTConfig::LoadFromFile(const char* configFN, char** args) 
{
    ifstream f(configFN, ios::in);
    CheckNTErrors(f.is_open(), "Failed to open the config file");

    int argsNum = 0;

    /* parse arguments from the file */
    string key, value;
    while (f >> key >> value && argsNum < (MAX_PARAM_NUM - 1)) {
        if (args[argsNum] != NULL) {
            delete[] args[argsNum];
        }
        if (args[argsNum + 1] != NULL) {
            delete[] args[argsNum + 1];
        }
        args[argsNum] = new char[1024];
        args[argsNum + 1] = new char[1024];
        strcpy(args[argsNum++], key.c_str());
        strcpy(args[argsNum++], value.c_str());
    }

    /* record the number of arguments */
    return argsNum;
}
/*
load configurations from a file
>> configFN - path to the configuration file
>> args - the list to store the configurations
<< argsNum - the number of arguments
format: one option per line, separated by a blank or a tab
*/
load configurations from a file
>> configFN - path to the configuration file
>> args - the list to store the configurations
<< argsNum - the number of arguments
format: one option per line, separated by a blank or a tab
load configurations from a file >> configFN - path to the configuration file >> args - the list to store the configurations << argsNum - the number of arguments format : one option per line separated by a blank or a tab
int NMTConfig::LoadFromFile(const char* configFN, char** args) 
{
    ifstream f(configFN, ios::in);
    CheckNTErrors(f.is_open(), "Failed to open the config file");
    int argsNum = 0;
    string key, value;
    while (f >> key >> value && argsNum < (MAX_PARAM_NUM - 1)) {
        if (args[argsNum] != NULL) {
            delete[] args[argsNum];
        }
        if (args[argsNum + 1] != NULL) {
            delete[] args[argsNum + 1];
        }
        args[argsNum] = new char[1024];
        args[argsNum + 1] = new char[1024];
        strcpy(args[argsNum++], key.c_str());
        strcpy(args[argsNum++], value.c_str());
    }
    return argsNum;
}
int NMTConfig :: LoadFromFile ( const char * configFN , char * * args ) { ifstream f ( configFN , ios :: in ) ; CheckNTErrors ( f . is_open ( ) , " " ) ; int argsNum = 0 ; string key , value ; while ( f >> key >> value && argsNum < ( MAX_PARAM_NUM - 1 ) ) { if ( args [ argsNum ] != NULL ) { delete [ ] args [ argsNum ] ; } if ( args [ argsNum + 1 ] != NULL ) { delete [ ] args [ argsNum + 1 ] ; } args [ argsNum ] = new char [ 1024 ] ; args [ argsNum + 1 ] = new char [ 1024 ] ; strcpy ( args [ argsNum ++ ] , key . c_str ( ) ) ; strcpy ( args [ argsNum ++ ] , value . c_str ( ) ) ; } return argsNum ; }
load configurations from a file
>> configFN - path to the configuration file
>> args - the list to store the configurations
<< argsNum - the number of arguments
format: one option per line, separated by a blank or a tab
load configurations from a file >> configFN - path to the configuration file >> args - the list to store the configurations << argsNum - the number of arguments format : one option per line separated by a blank or a tab
/* parse arguments from the file */ /* record the number of arguments */