two things you should know:
- getline read in a single line with "\n" delimiter by default, you can specify the delimiter
- >> will automatically skip white space and choose the right type for you
A stardard example
// ini.txt
numberofTest: 100000
kickPerTurn: 20
// code segment// it's import that you use ':' instead of ":"
ifstream ini_para("ini_parameters.txt");
if( ini_para.fail() )
cerr <<" failed to open ini_parameters.txt" ;
string dummy_string;
getline(ini_para,dummy_string,':');
ini_para >> numberofTest;A similar discussion could be found example on cplusplus.com.
cout << "numberofTest read as: " << numberofTest <<endl;
getline(ini_para,dummy_string,':');
ini_para >> kickPerTurn;
cout << "kickPerTurn read as: " << kickPerTurn <<endl;
ini_para.close();
No comments:
Post a Comment