2015-10-12 99 views
0

我在某種程度上是新的C++環境,我試圖將用java編寫的代碼轉換爲C++,並且我想問問任何人都可以幫助我在C++中找到與java Collection.frequency等效的東西。那我想轉化爲下面的代碼:C++等效於Java Collection.frequency?

List<Integer> foundCount = new ArrayList<~>(); 
.... // some code goes here 
... 
int count3 = Collections.frequency(foundCount,38); 

我真的很感激幫助

+1

does ['std :: count'](http://en.cppreference.com/w/cpp/algorithm/count)不適合你嗎? – NathanOliver

+0

其實我沒有使用std :: count,因爲我不知道它。但現在嘗試它的工作後。感謝您的幫助 – Albert

回答

1

的標準API提供std::count計數。

vector<int> v = {23 , 34 , 23 , 583 , 34 , 23}; 
cout << "23 appears " << count(v.begin() , v.end() , 23) << " times in v" 
    << endl; 
+0

這是我已閱讀你的答案後嘗試: 載體 findCount; int count 3 = std :: count(fountCount.begin(),foundCount.end(),38); ,它似乎工作...非常感謝你 – Albert