我将 c++ 代码保存在 .txt 文件中。我可以用 g++ 编译器格式化它吗?还是必须将其更改为 file.cpp?
为什么不能用 g++ 编译 .txt 文件?
谢谢您的回答。
答案1
从g++ 手册页:
You can specify the input language explicitly with the -x option:
-x language
Specify explicitly the language for the following input files
(rather than letting the compiler choose a default based on
the file name suffix). This option applies to all following
input files until the next -x option. Possible values for
language are:
c c-header cpp-output
c++ c++-header c++-cpp-output
objective-c objective-c-header objective-c-cpp-output
objective-c++ objective-c++-header objective-c++-cpp-output
assembler assembler-with-cpp
ada
d
f77 f77-cpp-input f95 f95-cpp-input
go
brig
所以,这样做g++ -x c++ file.txt
应该有效。