Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

c++ - How can I make Visual Studio save all files as UTF-8 without signature on Project or Solution level?

I am trying to configure a VS c++ project in a way that it can be compiled by gcc in Linux. It seems that I need the files to be encoded as UTF-8 without signature (which is not the default). Is it possible to set something on the project or solution level, so that after someone opens the solution and saves their changes the files are still UTF-8?

Please note that it is an open project, so I can't ask everyone to change their Visual Studio settings.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Visual Studio will remove the BOM by going to Save As... and selecting "Save With Encoding..." and selecting "UTF-8 without signature". Once it is saved without the BOM, VS will not add it again. Unfortunately, there is no way to make this default for all files in VS and must be done manually each time a file is saved for the first time.

If you have Cygwin installed you can batch modify existing files with this little script:

find . -name "*.cpp" -exec vim -c "set nobomb" -c wq! {} ;

Or, if you don't have Cygwin but you do have vim you can use this batch script.

for %%f in (*.cpp) do call vim -c "set nobomb" -c wq! %%f

Note, doing this in a batch script, it seems I need to hit [return] each time vim exits which isn't the case with the cygwin version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...