Author Topic: none english code in codeblocks, became unreadable code??  (Read 7021 times)

Offline zaazbb

  • Multiple posting newcomer
  • *
  • Posts: 14
none english code in codeblocks, became unreadable code??
« on: December 18, 2011, 04:42:33 am »
when my c++ code have chinese character, CodeBlock save file as UTF8 automatically,
 so my chinese character now is unreadable code. how to change it??

when i change file encode to window936, gcc compiler meet errors.??

How can i use none english code in codeblocks???
« Last Edit: December 18, 2011, 04:45:19 am by zaazbb »

Offline huzhongshan

  • Multiple posting newcomer
  • *
  • Posts: 109
Re: none english code in codeblocks, became unreadable code??
« Reply #1 on: December 18, 2011, 09:49:05 am »
I use chinese as "string" , donot meet such things.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5737
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: none english code in codeblocks, became unreadable code??
« Reply #2 on: December 18, 2011, 10:00:30 am »
so my chinese character now is unreadable code. how to change it??
Why?
You save your file in UTF8, and you should read/open it in UTF8.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline playxiaobaicai

  • Single posting newcomer
  • *
  • Posts: 5
Re: none english code in codeblocks, became unreadable code??
« Reply #3 on: December 18, 2011, 10:19:57 am »
I think you had better use English! After all, it's a English IDE.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: none english code in codeblocks, became unreadable code??
« Reply #4 on: December 18, 2011, 10:46:55 am »
when my c++ code have chinese character, CodeBlock save file as UTF8 automatically,
 so my chinese character now is unreadable code. how to change it??

when i change file encode to window936, gcc compiler meet errors.??

How can i use none english code in codeblocks???
Where is the code unreadable ?
Should be readable in C::B, if it is opened as utf-8.

Offline zaazbb

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: none english code in codeblocks, became unreadable code??
« Reply #5 on: December 19, 2011, 09:08:43 am »
when i build my project, the CB show a message as "encode changed ..", and my file save as utf8 automatily.   now, build and run my gui, the control text are unreadable. 

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: none english code in codeblocks, became unreadable code??
« Reply #6 on: December 19, 2011, 10:07:19 am »
That is not surprising, you're using different code pages when editing/compiling and running the program, so your Chinese characters come out as rubbish.

If you insist on writing Chinese in a non-Unicode program (which is somewhat unwise), you need to tell the compiler that you want to do such a thing, the switch for that would be something like -finput-charset=window936 for gcc. If you don't tell the compiler anything, it assumes UTF-8 encoding.

Otherwise, leave everything as it is in Code::Blocks and write a proper Unicode program (including L"" strings and the correct #defines for your toolkit/os) and you will have no such problems.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline zaazbb

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: none english code in codeblocks, became unreadable code??
« Reply #7 on: December 21, 2011, 03:41:11 pm »
That is not surprising, you're using different code pages when editing/compiling and running the program, so your Chinese characters come out as rubbish.

If you insist on writing Chinese in a non-Unicode program (which is somewhat unwise), you need to tell the compiler that you want to do such a thing, the switch for that would be something like -finput-charset=window936 for gcc. If you don't tell the compiler anything, it assumes UTF-8 encoding.

Otherwise, leave everything as it is in Code::Blocks and write a proper Unicode program (including L"" strings and the correct #defines for your toolkit/os) and you will have no such problems.

thank you very much!~~ ;D