Re: [問題] (C++) 比較麻煩的字串分割問題

看板C_and_CPP作者 (??)時間14年前 (2009/11/01 18:57), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《uhtmp (云浩天)》之銘言: : 爬文的結果, 似乎還是沒有找到解決方法@@" : 使用者輸入特定格式字串, 對字串做分割處理 : 使用者輸入: : "A. B. CDE" and "GG man" not "easy" (用 getline( buffer ) 存入buffer) : (PS: "ox OX" 引號中的內容長度不一可能有空白可能沒有) : 需要獲得的結果: : "A. B. CDE" : and : "GG man" : not : "easy" : 請問該怎麼對此格式字串做分割處理? : 若是以空白作為分割會出錯: : "A. : B. : CDE" : and : .......... : 試了很多方法, 還是沒有得到正確的結果>"< void func(char *str) { bool print_after_newline=1 int index=0; if(str[index=0]=='"') { cout<<str[index++]; print_after_newline=!print_after_newline; } while(str[index]!=0x00) { if(str[index]!='"') cout<<str[index++]; else if(print_after_newline==1) { cout<<'\n'<<str[index++]; print_after_newline=!print_after_newline; } else { cout<<str[index++]<<endl; print_after_newline=!print_after_newline; } } } -- 人們總是把大把大把的鈔票送進寺廟 卻無比厭惡路邊的乞丐、賣愛心筆、口香糖的人 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.47.235
文章代碼(AID): #1AxMcLlY (C_and_CPP)
文章代碼(AID): #1AxMcLlY (C_and_CPP)