Author Topic: Is there a method to save the source files in UTF-8 format in C::B?  (Read 10231 times)

Offline 00061205

  • Multiple posting newcomer
  • *
  • Posts: 30
Is there a method to save the source files in UTF-8 format in C::B?
In windows version C:B,the source files will not save by UTF-8 format. Gcc will report error if there are some local characters (eg. 中文) in the source files. If we convert the source files to UTF-8 format manually with other applications this problem will overcome.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #1 on: June 15, 2008, 05:04:45 pm »
Yes there is. Click-

1) Edit > File encoding > UTF-8.
2) Edit > File encoding > Save byte-order-mark (BOM)

The second option is necessary if you want to force every source files to be detected as UTF-8.
Be a part of the solution, not a part of the problem.

Offline 00061205

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #2 on: June 15, 2008, 05:17:31 pm »
Yes there is. Click-

1) Edit > File encoding > UTF-8.
2) Edit > File encoding > Save byte-order-mark (BOM)

The second option is necessary if you want to force every source files to be detected as UTF-8.
Thanks.
It works when just enable  Edit > File encoding > UTF-8. When I complie with both enabled I get this error message:E:\CodeBlocks\CBProjects\hword\hword.cpp|1|error: stray '\239' in program|

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #3 on: June 15, 2008, 05:27:32 pm »
Thanks.
It works when just enable  Edit > File encoding > UTF-8. When I complie with both enabled I get this error message:E:\CodeBlocks\CBProjects\hword\hword.cpp|1|error: stray '\239' in program|

Try adding -finput-charset=utf-8 to compiler options.
Be a part of the solution, not a part of the problem.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #4 on: June 15, 2008, 06:33:30 pm »
Rather, add no option, and don't use that byte order mark. UTF-8 is gcc's default encoding.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline 00061205

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #5 on: June 16, 2008, 11:06:37 am »
I must manually enable edit->file encoding->utf-8 before i compile a new file which contain unicode characters.
How to set C::B handle file in UTF-8 format defaultly?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9594
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #6 on: June 16, 2008, 11:21:49 am »
How to set C::B handle file in UTF-8 format defaultly?
Settings -> Editor -> General Settings -> (in the "font" part:) "Default encoding when opening files"
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline 00061205

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: Is there a method to save the source files in UTF-8 format in C::B?
« Reply #7 on: June 16, 2008, 02:21:13 pm »
How to set C::B handle file in UTF-8 format defaultly?
Settings -> Editor -> General Settings -> (in the "font" part:) "Default encoding when opening files"

Thanks MortenMacFly.