HACKER Q&A
📣 mardiyah

Have GNU C++ compiler ignore shebang


Any Guru of C++ so solve this error below making GNU c++ ignore shebang?

m.cpp:1:2: error: invalid preprocessing directive #!

    1 | #!/usr/bin/vim
Please do favor solve it, thanks so much


  👤 coreyp_1 Accepted Answer ✓
I don't think that this is possible.

The `#` is not a valid comment in C++, and `#!` is not a valid preprocessor directive, hence the error.


👤 kazinator
There is no way to solve this so that you have a single file X.cc that you can feed to g++ as an argument:

  g++ X.cc ...
and such that this file is a hash bang script.

C and C++ can be hash-bang scripted, through a shell script which cuts out the incompatible material and feeds the rest to the compiler. See the solution for the multiline shebang task in Rosetta Code:

https://rosettacode.org/wiki/Multiline_shebang#C

I'm guess you're trying to make the program self-editing rather than self executing, by using Vim as the interpreter?


👤 gsteele178
Try{ #include!/user/bin/vim Return!O

👤 gsteele178
#include¡ //user/bin/vim