删除 std::set<vector<string>>::iterator 索引处的值

Remove value at index of std::set<vector<string>>::iterator

更新——这个问题可能与(Use iterator to call the non-static function in STL Set)

相关

我正在创建一个程序来扫描和解析文本文件、创建数据库并根据方案和事实评估查询。我的数据结构如下:

Relation
    Scheme
    set<Tuple>

其中 SchemeTuple 继承自 std::vector<std::string>Scheme 和每个 Tuple 应该有相同数量的元素,我反复需要删除所有三个中某个索引处的值。例如,如果我有:

Scheme
    C D H
Tuples
    EE200 F 10AM
    EE200 M 10AM
    EE200 W 1PM

组织如下:

  C='EE200' D='F' H='10AM'
  C='EE200' D='M' H='10AM'
  C='EE200' D='W' H='1PM'

在每个向量的索引 0 处删除后我应该有:

  D='F' H='10AM'
  D='M' H='10AM'
  D='W' H='1PM'

我已经写了 this code 来用一个例子来定位问题。我首先擦除 Scheme 中的索引(它本质上是一个字符串向量),然后遍历集合中的每个 Tuple 并尝试删除索引处的值。在我的示例中,我放弃了创建 类 而只是使用了 std::stringstd::vector<std::string>。问题在这里:

    for(set<vector<string>>::iterator t = tempTuples.begin(); t != tempTuples.end(); ++t)
    {
        // how do I erase the element at t?  
    }

其中 tempTuplesTuple 对象的集合(这里只是字符串向量)。 (*t).erase((*t).begin()) 此时插入会报错(no matching member function for call to 'erase')。如何删除此处索引处的值?

如果您查看错误,您会发现问题出在您有一个 const_iterator。这是因为 set 自动 returns const 迭代器,如 this question.

中所述