[問題] qt的list容器可以作條件count嗎
開發平台(Platform): (Ex: Win10, Linux, ...)
win7
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
vs2015
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
qt 5.7
問題(Question):
請問qt的list容器可以做條件count嗎
例如我有一個 mylist[5] = {5, 7, 1, 2, 4};
想要找出這個mylist裡面大於5的數字
python 可以寫成
newList = [i for i in mylist if i>=5]
newList.count();
餵入的資料(Input):
請問Qt的容器裡面有類似的寫法嗎 還是只能這樣
QList<int> mylist;
mylist << 5 << 7 << 1 << 2 <<4;
QList<int> newList
for(int i = 0; i < list.size(); ++i) {
if(mylist[i]>=5){
newList.append(mylist[i]);
}
}
qDebug()<< newList.count();
預期的正確結果(Expected Output):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.124.46.66
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1487732422.A.764.html
推
02/22 11:40, , 1F
02/22 11:40, 1F
→
02/22 11:42, , 2F
02/22 11:42, 2F
→
02/22 11:42, , 3F
02/22 11:42, 3F
→
02/22 11:45, , 4F
02/22 11:45, 4F
→
02/22 11:50, , 5F
02/22 11:50, 5F