删除矢量数据,不要向前推进
Delete vector data and not to push forward
我有一个向量,它的数据为
战绩1:03:泰德
记录2:06:玛丽
战绩3:23:渡轮
如何删除Record 2
,以使Record 3
数据不会向上推送并最终变得Record 2
?
如果我理解正确,请使用记录编号到记录的映射:
std::unordered_map<std::size_t, Record> records{ //or std::map in C++03
{1, {"03", "Ted"}}, //or records[1] = Record("03", "Ted") in C++03
{2, {"06", "Mary"}}, //or records[2] = Record("06", "Mary") in C++03
{3, {"23", "Ferry"}} //or records[3] = Record("23", "Ferry") in C++03
};
records.erase(2); //leaves records[1] and records[3] intact
有关完整的演示,请参阅此处 fpr C++11,或此处的 C++03,尽管 C++03 可以通过 insert
进行改进,因此不需要Record
的默认构造函数。我想 C++11 在迭代时也可以使用 const
,尽管这无关紧要。
相关文章:
- 从 Typedef 数据类型中删除常量
- 从输入中删除重复项,而不使用任何数据结构
- 删除使数据处于"错误状态"的默认构造函数的模式?
- 从自定义数据类型向量中删除重复元素
- 如何使用C++删除/更新txt文件中的特定数据
- 如何使用C++删除/更新txt文件中的特定数据?
- 从文本文件中读取数据并删除所有换行符空格,并在 C++ 控制台中显示
- C++ - 按自定义数据类型向量的值删除元素
- 如何从 txt 文件中删除数据/内容
- 如何通过其持有的数据从链表中删除某个节点?
- 基于给定字符串数据类型的链表删除节点
- 如何在 C++ 中使用删除运算符删除单个数据
- 如何在每次循环迭代期间生成向量,存储数据,然后删除该向量?
- 如何从C ++的输出中删除垃圾数据(垃圾数据)
- 如何从 HTTP 响应中删除垃圾数据
- C++ 类析构函数删除部分但不是全部成员数据
- 在向量上调用 clear() 实际上不会删除 data() 中的数据?
- SOCAT,将TCP套接字转发到Unix套接字,将recvmsg()更改为read(),删除辅助数据
- 如何删除字符串中的所有空格并将数据存储在两者之间
- 筛选器重复列表-列出重复数据删除