In this piece of code, in every iteration of while loop, a line is read from a file. The line is something like:
13,4636137,29464742,29464746,995560164
for every number specified in bold, the existence of that number as a key in a std::map is checked in a for loop. If the key exists, then the value is appended to the string. Then the string is written to the file.
If one of keys not exist in the map, then for that line nothing should be written to the file. (bool is_points_in_range)
But in practice, in the cases that the last point (outside of for loop) is not in key list, the program logic performs well.
Why the boolean operator does not change in for loop?
vector<string> res;
ifstream infile;
map<string, string> m;
while(infile.getline(buffer, LINE_BUFFER_LEN))
{
line=string(buffer);
res = SplitBySep(line, ",");
bool is_points_in_range=true;
string geo_file_line;
for (int i=2;i<res.size()-1;i++){
if ( m.find(res[i]) == m.end() ) {
is_points_in_range=false;
break;
} else {
geo_file_line= geo_file_line.append(m[res[i]]).append("^");
}
}
if ( m.find(res[res.size()-1]) == m.end() ) {
is_points_in_range=false;
} else {
geo_file_line= geo_file_line.append(m[res[res.size()-1]]).append("\n");
}
if (is_points_in_range){
fprintf(fp_geo, "%s",geo_file_line.c_str());
}
}