Re: [問題] c++將字串排序

看板C_and_CPP作者 (師大狗鼻哥)時間9年前發表 (2016/05/10 13:20), 9年前編輯推噓1(104)
留言5則, 4人參與, 最新討論串2/4 (看更多)
※ 引述《cchou0114 (嘻嘻)》之銘言: : 如題 : 我想要將字串排序 : 例如有3個字串 : 分別存在一個字串陣列中 : string word[]; : word[0]="Hello"; : word[1]="World"; : word[2]="Bye"; : 要怎麼把他依照字首順序排序呢 : 變成這樣 : word[0]="Bye"; : word[1]="Hello"; : word[2]="World"; : 求各位大大給個意見或提示 : 謝謝! #include <algorithm> sort(word,word+3, [](auto a, auto b){ return a[0] > b[0]; }); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.138.244.200 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1462886430.A.726.html

05/10 21:23, , 1F
我猜他會跟你說不能用STL
05/10 21:23, 1F

05/10 21:24, , 2F
不會那麼慘吧,他都用string了
05/10 21:24, 2F

05/10 22:08, , 3F
"=>" 是寫錯了吧
05/10 22:08, 3F

05/10 22:10, , 4F
是喔
05/10 22:10, 4F

05/11 07:12, , 5F
寫其他語言的lambda寫習慣了....
05/11 07:12, 5F
※ 編輯: soheadsome (223.141.203.169), 05/11/2016 18:10:07
文章代碼(AID): #1NCU0USc (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1NCU0USc (C_and_CPP)