看板 C_and_CPP 關於我們 聯絡資訊
開發平台(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
dododavid006: 用 c++ 函式庫的 count_if + c++11 的 lambda 就行 02/22 11:40
uranusjr: QList 有遵循 STL API http://d.pr/l1hO 02/22 11:42
uranusjr: 啊輸給樓上了 XD 02/22 11:42
dododavid006: 差點就輸了XD 剛剛我在測試 也把 code 貼上來吧 02/22 11:45
dododavid006: 我有用到 c++14 的功能就是了https://goo.gl/CRt4V0 02/22 11:50