text file processing using string
I am seeking a better solution to process a text file.
The task is, I want my C++ program to read various varibles given in a configuration text file that user can specify variuos varible parameters. These varibles have predetermined names that C can search in the text file, then following these variable names, C can identify what values should be given to them. For example, in the configuration text file called "cfg.txt", there are lines given as:
...
mode = 'automatic'
initial_value = [1.0 0.0 -2.5 0]
frequency = 250 Mhz
...
in this configuration text file, C function is expected to search the key names: mode, initial_value, and frequency, the running result should be given them values (char * or string) as 'automatice', vector as [1.0 0.0 -2.5 0], and double value as 250. Other lines can be anything just as comments.
Currently, I am using following:
ifstream fin("cfg.txt", ios::in);
if(!fin){
cerr<<"File could not be opened!\n";
exit(1);
}
struct input_para t;//input struct to store the read out values
char x[200];
fin.seekg(0,ios::beg);
while(!fin.eof()){
fin.getline(x,200);
if(x[0]=='\0') continue;
... // char by char to process/search line by line.
}
...
But I am not satisfied with this style, I want to use string and its library to give an efficient and more flexiable process.
Anybody has good suggestion to do that using STD string styles?
Thanks in advance.
Alvinw

