map< string, vector > 是否不支持中文内容?(包括值)

xiaofengzzz 2009-07-21 10:13:00

各位,简单说是,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;
}
...全文
338 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hawkfeifei 2009-07-21
  • 打赏
  • 举报
回复
中文也是字符串,map、string、vector当然支持,出现乱码是楼主的编码有问题
  • 打赏
  • 举报
回复
你是想问map支持自定义类型的键值末?
http://topic.csdn.net/u/20071224/12/4c65b69b-736f-43ae-9474-9c9977cd3f68.html
Jagen在路上 2009-07-21
  • 打赏
  • 举报
回复
标准容器跟具体文字编码没有关系啊。
taodm 2009-07-21
  • 打赏
  • 举报
回复
和map、vector、string没关系,它们都支持中文。
而是楼主完全不懂 中文编码方式,不知道gb2312 什么的是什么意思。
superbtl 2009-07-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 njzhiyuan 的回复:]
中文的话,可用wstring
[/Quote]顶 看看字符集 在不同系统也是不一样的
超gogo 2009-07-21
  • 打赏
  • 举报
回复
支不支持中文和字符码有关,和容器之类的无关
njzhiyuan 2009-07-21
  • 打赏
  • 举报
回复
中文的话,可用wstring

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧