0


I have c++ code saved in .txt file. Can i somehow format it with g++ compiler or i\ must change it to file.cpp?
Is there why how to compile a .txt file with g++?
Thanks for answare.

2
  • I doubt it will work, but try and see: g++ -c file.txt.
    – harrymc
    Commented Apr 26, 2021 at 8:10
  • Hi @harrymc I tried it but it show an error:\ g++: warning: Skus.txt: linker input file unused because linking not done.
    – Filip
    Commented Apr 26, 2021 at 16:06

1 Answer 1

0

From g++ man page:

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

So, doing g++ -x c++ file.txt should work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .