在C ++中创建多级哈希/字典 [英] Multi level hash/dictionary creation in C++

查看:638
本文介绍了在C ++中创建多级哈希/字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点失落。我有一个csv文件,如下所示

I am a bit lost. i have a csv file like the following

USN Name   DOB   Sem   Percentage
111 abc   07/03   3      88
112 cde   18/07   4      77
123 ghi   15/11   4      80

I想要使用C ++创建一个字典类型的结构(多级字典 -
Dictionary< string,Dictionary< string,string>>
。这里我想存储第一行作为键,即USN,Name,DOB ...作为散列的键和列中的值作为散列的值。
是可能吗?
任何帮助将非常感谢..提前感谢。

I want to create a dictionary kind of structure (multilevel dictionary- Dictionary <string, Dictionary<string, string>>) using C++. Here i want to store the 1st line as key i.e USN, Name, DOB ... as keys of the hash and the values in that columns as values of the hash. Is it possible? Any help will be greatly appreciated .. Thanks in advance.

推荐答案

code> unordered_map ,这是C ++ 11中的标准,在以前的实现中非常常见。如果性能不太重要(或者map真的很小),你也可以使用 map 。那么你可以这样做:

Given your question, you should be using unordered_map, which is standard in C++ 11 and very common in previous implementations. If performance is not too important (or the maps really small) you can also use map. Then you can do this:

using namespace std;
unordered_map<string, unordered_map<string, string> > dict;

之后,这是一个解析CSV文件的问题...

After, it's a question of parsing your CSV file ...

这篇关于在C ++中创建多级哈希/字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆