将具有多个点(版本号)的格式的数字转换(转换)为字符串

San*_*ich 1 c++ string

#define EXTERNAL_API_VERSION 1.12.1
std::string version = boost::lexical_cast<std::string>(EXTERNAL_API_VERSION);
Run Code Online (Sandbox Code Playgroud)

此代码生成编译错误:

error C2143: syntax error : missing ')' before 'constant'
error C2059: syntax error : ')'
Run Code Online (Sandbox Code Playgroud)

是否有任何简单的替代方法可以将这种格式(多于一个点)的数字转换为字符串?

mas*_*oud 5

无需触摸EXTERNAL_API_VERSION,您需要将两个级别的marco扩展为字符串文字:

#define S(X) #X
#define STR(X) S(X)

std::string version = STR(EXTERNAL_API_VERSION);
Run Code Online (Sandbox Code Playgroud)