Re: [問題] 比對UTF8檔案中的中文字串

看板C_and_CPP (C/C++)作者 (御風只配做笨木頭)時間16年前 (2009/05/14 10:15), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《msjs (qq)》之銘言: : 目的是要判斷我輸入的某字串 是否有出現在.txt的檔案中 : 而該文字檔是以UTF-8的方式存檔 : 大概的方法是將文字檔一行一行讀下來 再判斷 : 程式截部份如下 : char line[10240]; : file.getline(line, sizeof(line)); : if(strstr(line, "字串" ) !=NULL) : cout<<"發現了"<<endl; : 結果英文都可以 但是字串是中文就比對不到 : 請問該怎麼解決? : → msjs:我是用VC++2008 05/14 01:32 : 推 legnaleurc:your source code should be utf8 05/14 01:52 : → msjs:怎麼改成UTF8 05/14 01:53 VC++2008 只認 BOM,把 source code 改成 utf8,要記得加上 BOM。 一般程式設計用的 editor 都有這個功能,再不行就貼到 WinXP 以上 的記事本,另以 utf-8 存檔。Notepad 存 unicode 一定會加上 BOM。 但是,程式碼裡面出現中文字,是不標準的作法,請見相關拙作: - GCC and customizable input source charset http://www.jeffhung.net/blog/articles/jeffhung/383/ - Subversion Issue 2332: Keyword expansion in non-UTF8 documents results in mixed charsets http://www.jeffhung.net/blog/articles/jeffhung/473/ -- 我的微笑,堅持要有鼻子。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.250.103.120
文章代碼(AID): #1A2twiEe (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1A2twiEe (C_and_CPP)