lit*_*tro 0 c++ char include stringify
我想在C++中执行以下操作:
static const char* data[] = { #include "mydata.hh" };
Run Code Online (Sandbox Code Playgroud)
其中mydata.hh的内容应该被指定为数据的char数组.我已经尝试了#include的各种变体和(一级和两级)字符串化#x.到目前为止没有工作.这实际上是可能的还是我错过了什么?
谢谢你.
您可以:
static const char* data[] = { // <--- new line
#include "mydata.hh"
}; // <--- don't forget semi-colon
Run Code Online (Sandbox Code Playgroud)
但为什么?
这是假设mydata.hh包含与声明兼容的东西:
//mydata.hh
"bla", "goo", "foo"
Run Code Online (Sandbox Code Playgroud)