I would like to get some advice on an issue I've encountered once working on small adjustments to an existing program.
The program itself has to:
- Open a file and read it line-by-line preferably
- Pack the lines into
istringstream
and then split to 2 strings on a':'
separator - Insert those 2 strings
line1
andline2
into an existingstd::map
container - Than I can do more stuff with the
map
and the data from it.
My code looks like that:
int main()
{
FILE *fpFile;
map<string, string>mapOfPci;
std::string tempBuff="";
std::string line1="", line2="";
fpFile = fopen(PCI_MAPPING_PATH, "r");
if(!fpFile)
return false;
while(getline(fpFile, tempBuff)){
istringstream iSs(tempBuff);
iSs >> line1;
iSs.ignore(numeric_limits<std::streamsize>::max(), ':');
iSs >> line2;
mapOfPci.insert(make_pair(line1, line2));
}
for(const auto &m : mapOfPci){
cout << m.first << " : " << m.second << "\n";
}
fclose(fpFile);
return (0);
}
Now what I'm getting in my compiler feedback is:
mismatched types 'std::basic_istream<_CharT, _Traits>' and 'FILE* {aka _iobuf*}'
while(getline(fpFile, tempBuff))
At this point I presume that this is due to the usage of FILE*
file handling method.
I might not be able to use the C++ std::ifstream
, std::fstream
, so is there any method to move this further with the current FILE*
usage?
Aucun commentaire:
Enregistrer un commentaire