map< string, vector > 是否不支持中文内容?(包括值)
各位,简单说是,map容器不支持中文做索引,这我能理解,可为什么在这个容器中的值:vector<string> 都不支持了呢?
可以简单的讲解下吗?
以下是我根据书上做的练习题,如果:给出的文档值部分包括中文,就会乱码,如果是索引部分也是中分,就不能查找,
___________________________________________________________________________________________________________
#include <iostream>
#include <map>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
int main()
{
map< string, vector<string> > map_string;
ifstream input;
string input_file;
while (true)
{
input.close();
input.clear();
cout << "输入文件名: ";
getline(cin, input_file);
input.open(input_file.c_str());
if (input)
break;
else
cout << "指定的文件不存在,确认后重新";
}
while (getline(input, input_file))
{
istringstream stream(input_file);
vector<string> name;
string word;
pair< map< string, vector<string> >::iterator, bool > ret;
stream >> input_file;
name.push_back(word);
ret = map_string.insert(make_pair(input_file, name));
while (stream >> input_file)
{
(ret.first->second).push_back(input_file);
}
}
/* for (map< string, vector<string> >::iterator it = map_string.begin(); it != map_string.end(); ++it)
for (vector<string>::iterator iter = (it->second).begin(); iter != (it->second).end(); ++iter)
cout << *iter << "\n";
cout << endl;
*/
while ( true )
{
cout << "输入查询的姓: ";
cin >> input_file;
if (input_file == "break" || input_file == "esc" )
break;
map< string, vector<string> >::iterator it = map_string.find(input_file);
if (it != map_string.end())
{
for ( vector<string>::iterator iter = (it->second).begin(); iter != (it->second).end(); ++iter)
cout << *iter << "\n";
cout << endl;
}
else
cout << input_file << " 不存在,请确认后重输出入.\n";
}
return 0;
}