Is it possible to read a file at compile time?

前端 未结 3 1385
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 13:21

I am wondering if it is possible in C++11/14 to actually read files at compile time. For example the following code will only compile if it can successfully read the file.

3条回答
  •  鱼传尺愫
    2020-12-03 14:07

    I have done something like this. See if this will give you what you want.

    Add a command line option to the program that checks for the existence and validity of the input file.
    That option should exit the program with an error code if the file does not exist, or is not valid.

    In your make file, add a call to the program (using that command line option), as the final build step.

    Now when you build the program, you will get an error if the proper files are not available or not valid.

提交回复
热议问题