I had a problem getting a program to read from a file based on a template, for example:
bool parse(basic_ifstream<T> &file) { T ch; locale loc = file.getloc(); basic_string<T> buf; file.unsetf(ios_base::skipws); if (file.is_open()) { while (file >> ch) { if(isalnum(ch, loc)) { buf += ch; } else if(!buf.empty()) { addWord(buf); buf.clear(); } } if(!buf.empty()) { addWord(buf); } return true; } return false; }
This will work when I create this class using <char> , but has problems when I use <wchar_t> (clearly).
Outside the class, I use:
for (iter = mp.begin(); iter != mp.end(); ++iter ) { cout << iter->first << setw(textwidth - iter->first.length() + 1); cout << " " << iter->second << endl; }
To write all the information from this data structure (this is a map<basic_string<T>, int> ), and, as predicted, cout explodes if iter->first not a char array.
I looked online and the consensus is to use wcout, but unfortunately, since this program requires that the template can be changed at compile time ( <char> → <wchar_t> ), I'm not sure how I can avoid just choosing cout or wcout. That is, if there is no way to read / write wide characters without changing a lot of code.
If this explanation sounds awkwardly complicated, let me know and I will address it as best as possible.
source share