Include one header file in each source file

后端 未结 4 544
心在旅途
心在旅途 2021-01-19 14:50

Say you have 100s of source files (.c or .cpp) files, and you want to include some definitions, function/variable declarations in each of them. Normally in C/C++, you use he

4条回答
  •  别那么骄傲
    2021-01-19 15:31

    Yes, it would be tiresome. This is why you uses the shell...

    The following mystical incantation will do exactly what you ask in a few keystrokes!

    find ./ -name "*.c" -or -name "*.cpp" | xargs -n 1 sed -i '1 i #include '
    

    Bow down to the mighty power of unix, heathens...

提交回复
热议问题