0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

マクロ引数に与えられたパラメーターを文字列として展開させる。

Last updated at Posted at 2020-02-18

C++でマクロを使う。

マクロに渡された引数を文字列に展開して扱う事が可能。
以下に出力された通り。

どうするか
マクロ引数の先頭に'#'をつける。

c++
# define PRINTX(x, v)  printf(#x, v);

int main()
{
    int n=0;
    PRINTX("%d\n", n);
    printf("\n");
    PRINTX(%d\n, n);
}
出力
"0\n"
0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?