I usually read a config file for my application with a " : " delimiter e.g. :
And after I read the whole line into a string, I "tokenize" it with sscanf like so:Code:#name : filename : value : boolstate (0 = false / 1 = true) myConf : config.txt : 2000 : 1
I understand sscanf is a method from C, so if I wanted to make it more C++, what should I use? Or maybe there's some better way to scan the values from the string that can directly convert the variable type (e.g. from "1000" from the file to int(1000) )? Thanks in advance.Code:ifstream myFile; myFile.open("myconfig.cnf"); char buffer[255]; myFile.getline(buffer, 255); int res; char tempName[255]; char tempFile[255]; int value, tempBool; res = sscanf ( buffer, "%s : %s : %d : %d", tempName, tempFile, &value, &tempBool); std::string name=tempName; std::string filename=tempFile; bool state=tempBool;



LinkBack URL
About LinkBacks



