【发布时间】:2013-10-22 09:12:30
【问题描述】:
我正在尝试将 ascii 代码和名称放入列表向量中:理想情况下它会是这样的:
97:“真棒”、“全部”
98:“最佳”、“轰隆”、“炸弹”
99:“猫”
我有
class index_table
{
public:
index_table() { table.resize(128);}
void insert(string &, int);
private:
class entry { //Subclass
string word;
vector <int> line;
}
vector< list <entry > > table;
那么我怎样才能正确地将这些单词和ASCII码放入列表的向量中呢?
在 main 中我尝试了一些语法,但它不起作用:
void index_table :: insert ( string & word, int num) //This is the code for "cat" and "99"
{
entry obj;
//This is the part I'm not sure about. How do I enter each word and num into the vector < list < entry >> table
}
希望我说得足够清楚。总而言之,我对 vector > 表的工作方式感到困惑。或者更确切地说,我如何才能正确存储我的号码和单词?
【问题讨论】:
-
为什么不简单地
std::map<int, std::vector<std::string> >? -
@P0W:我认为key -> entry的原因,其中entry包含单词+行号是因为他正在研究某种搜索索引。
-
@LihO idk,但
vector<int>forline对于给定的示例没有意义