【发布时间】:2021-02-14 05:25:20
【问题描述】:
我有一个文本文件,它是一对“字符-二进制代码”的字典。我需要从文件中读取该字典并将值放入 map
我的字典文件:
'0111010
,110110
.11110101
:110101011
;111101000
A0011010
B01110011
I0011011
S01110110
T0111000
W01110111
Y111101001
a0000
b1111011
我的代码:
vector<bool> CharCode;
char key;
char code;
string str;
map<char, vector<bool> > dict;//associative array of charater and its binary code
ifstream Dictionary(Dict);
while (getline(Dictionary, str))
{
std::cout << str << "\n";
//But how to put the key and code to char and vector<bool> respectively?
}
Dictionary.close();
【问题讨论】:
-
您可以使用
map[key] = valueassignments 来填充地图。 -
@UlrichEckhardt 但该值不是一个简单的变量,它是一个向量。我觉得我不会工作
-
@brc-dd 非常感谢!现在我明白了
标签: c++ dictionary vector