finding a particular string in a readin file
Hello,
I have a file that I'm reading in.. i.e. :
\version: someexample
\file: somefile
\testsize: sometest
\datapoint: somepoint
when I read it in I need to be able to look at th file and check for a particular thisg: example: I need to be able to check for the string "\testsize: " and then bring in the (integer) sometest and store it in some variable.
I know how to read in a file:
int sometest;
ifstream infile("myfile");
//I am not sure how to check for the string "\testsize: " and
// read in the number that it is assigned...
infile >> sometest;
any help will be greatly appreciated.... thanks
need help with finding a string and then reading its value
hello,
I am hoping someone can help me...I'm having quite a bit of problems with this...
I outlined the problem above...but basically I am reading in a file, I'll give a small sample of what the file contains:
/scan size: 123
/scan size2: 1234
/zsize: 90
this list is long and most of the components are of not interest.
so, while reading in...I want to be able to look for string: "/scan size: " or "/zsize: ", and I want to read in the numbers that are listed for those paramenter, i.e: for "/scan size: " I want to store 123, for "/zsize: " I want to store 90, I can't figure out how to do this....this is what I wrote:
void readheader(char *infile){
ifstream input(infile);//this is just the file that I'm getting
char filein[30];
strcpy(filein, infile);
char str[] [20]= { "\Scan Size: ", "\Z sensitivity: ", "\Z max: "};
int n;
float scansize1;
ifstream in(filein);
if (in.is_open()) {
while(in ){
if(strncmp (str[n], "\Scan Size: ", 12) == 0) {
in>>scansize1; //so here it would see "\Scan Size: " and
//should read in the value that's listed beside it...
} } }
//just to check if it did read the right number
cout<<"this is the scansize: "<<scansize1;
in.close();
}//end readheader
I ran this, it complied, but not doing anything...I'm really not sure how to code this and need help.....thanks for any help....