2017-10-20 96 views

回答

0

元素的行給出錯誤設置不被索引訪問。 s [i]是(i-1)'th集合,但s [i] [j]並不意味着什麼。您可以使用find函數檢查組中是否存在元素。例如s [i] .find(3)!= s [i] .end()。您可以使用for(int x:s [i]){}(C++ 11及更高版本)或使用迭代器按排序順序循環元素。

3

問題不在於數組std::set -s,而在於您嘗試訪問設置中的元素的方式。

std::set不支持operator [],這就是爲什麼你所得到的錯誤:

no match for 'operator[ ]'

相反,以下列方式使用find()訪問對象:

auto iter = s[i].find(<value>); 
if (iter != s[i].end()) { 
    [..] // Do something with iter 
} 
相關問題