I have a problem with umlauts (letters ä, ü, ö, ...) and ifstream in C ++.
I use curl to load an html page and ifstream to read the downloaded file line by line and parse some data from it. This is good as long as I don't have a string, as one of the following:
te="Olimpija Laibach - Tromsö"; te="Burghausen - Münster";
My code parses these lines and outputs them as follows:
Olimpija Laibach vs. Troms? Burghausen vs. M?nster
Things like umlauts output directly from code:
cout << "öäü" << endl;
My code looks something like this:
ifstream fin("file"); while(!(fin.eof())) { getline(fin, line, '\n'); int pos = line.find("te="); if(pos >= 0) { pos = line.find(" - "); string team1 = line.substr(4,pos-4); string team2 = line.substr(pos+3, line.length()-pos-6); cout << team1 << " vs. " << team2 << endl; } }
Edit: The strange thing is that the same code (the only thing changed is the source and delimiters) works for a different text input file (same procedure: loading with curl, reading with ifstream), Parse and output a line like following, no problem:
<span id="...">Fernwärme Vienna</span>
source share