我在使用基于模板的文件读取程序时遇到问题,例如:
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;
}
Run Code Online (Sandbox Code Playgroud)
这将在我实例化这个类时有效<char>,但在我使用时<wchar_t>(显然)有问题.
课外,我正在使用:
for (iter = mp.begin(); iter != mp.end(); ++iter )
{
cout << iter->first << setw(textwidth - iter->first.length() + 1);
cout << " " << iter->second << endl;
} …Run Code Online (Sandbox Code Playgroud)