My file has these lines.
I try to remove extra line in the end, in notepad/gedit, however, after saving it automatically adds up there.
Code:
void help::read_ref(const char* file_name){
std::ifstream file_handle;
file_handle.open(file_name);
std::string line,name;
getline(file_handle,line);
while(!file_handle.eof()){
if(line[0]=='>'){
name=line.substr(1,line.length()-1);//taking selected chars
reference[name]="";
}
getline(file_handle,line);
}
file_handle.close();
std::cerr<<"file reading done"<<"\n";
}
//when I print size of map, it comes out to be an extra then what is should be.
std::map<std::String,std::string> ->is my map
on the contrary if I use
Code:
file_handle >> line;
I get correct number of entries in map.
My doubt: getline, automatically finds \n and in last, it finds a \n, why it doesn't end the iteration?
I have faced this issue many number of times.
Please guide.
I am making this check, then also, I get a null string as key in my map.
I have printed key with their index, using .