3

2 つのマップがあり、違いを見つけて、違いだけを持つ新しいマップを作成する必要があります。これを行う方法がわからない。set_difference を使用してみましたが、その仕組みがよくわかりません。どんな助けでも大歓迎です。ありがとう

// header file
typedef std::map<std::string, int> MapCol;
typedef std::map<std::string, MapCol> MapRow;
MapRow m_mapRows;

//.cpp fle
CheckForDifferences( const Table& rhs )
{
    Table diffTable;
    vector<string> v;                           
    vector<string>::iterator it;
    it=set_difference (m_mapRows.begin(), m_mapRows.end(), diffTable.m_mapRows.begin(), diffTable.m_mapRows.end, v.begin());
}

編集:

std::set_difference( m_mapRows.begin(), m_mapRows.end(),
rhs.m_mapRows.begin(), rhs.m_mapRows.end(), diffTable.m_mapRows.begin());

これは私が試したものですが、最初のエラーはエラー C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (または受け入れ可能な変換がありません) です)

何か案は?

4

3 に答える 3

5

If you have two sorted containers a and b and you want to copy the set of objects that aren't in either one into another container c, you'd do this:

std::set_symmetric_difference(
    a.begin(), a.end(),
    b.begin(), b.end(),
    std::back_inserter(c) );

If you just want the elements from a that aren't in b, use set_difference instead of set_symmetric_difference.

于 2012-11-02T19:07:18.213 に答える