What is the best encoding for C ++ source code

I recently moved the encoding of my C ++ sources from ASCII to UTF-8, but I'm not sure if that's a good idea as I have some problems with literals and now I'm slowly thinking, I don't see any advantage.

What encoding would be considered standard or "best practice" in C ++ sources? (my ides are VStudio and QtCreator, but I suppose this question is general)

+3


source to share


3 answers


I would say UTF-8 is the right choice if all the implementations you use support it.

The advantages are that you don't have to write every non-ascii character with spaces \uXXXX

or \UXXXXXXXX

. Or, if "ASCII" you really mean one of the various locale specific encodings / codepages, using UTF-8 has the advantage that it works on all local networks and does not require developers to configure their (Windows) machine to locale in order to create the source.



If you describe the problems you have with literals, I can probably help you solve them.

+1


source


Don't put non-ASCII characters in your source code. Then the encoding doesn't matter.



This is sad but true for a cross-platform project, which is the safest and most reliable option.

+1


source


From the 2.3.1 standard:

Character sets [lex.charset]

1 The main character set of the source consists of 96 characters: the space character, control characters representing horizontal tab, vertical tab, feed and newline, and the following 91 graphic characters:

abcdefgh i jklmnopqrstuvwxyz

ABCDEFGH i JKLMNOPQRSTUVWXYZ

0 1 2 3 4 5 6 7 8 9

_ {} [] # () <>%:;,? * + - / ^ and | ~! =, \ "

0


source







All Articles