小编Joh*_*ohn的帖子

在printf中使用#define?

我想要为应用程序ID使用某种常量(所以我可以在printf中使用它).

我有这个:

#define _APPID_ "Hello World!"
Run Code Online (Sandbox Code Playgroud)

然后是简单的printf,将其调用为%s(字符串).它说出来了:

simple.cpp:32: error: cannot convert ‘_IO_FILE*’ to ‘const char*’ for argument ‘1’ to ‘int printf(const char*, ...)’

我将使用什么来定义要在printf中使用的应用程序ID?我试过了:

static const char _APPID_[] = "Hello World"`
Run Code Online (Sandbox Code Playgroud)

但它没有用,我认为同样的错误.

c++ string c-preprocessor

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

c-preprocessor ×1

string ×1