// N はビット幅 (8, 16, 32, 64 など)
#define SCNbN implementation-defined
概要
<cstdint>の固定幅整数型を、std::scanf系関数で2進数として入力するための変換指定子を表すマクロ。"%" SCNb16 のように文字列リテラルと連結して書式文字列を構成する。
C23で<inttypes.h>に追加されたマクロであり、C++26で<cinttypes>に取り込まれた。
対象とする整数型に応じて、以下のマクロが定義される (Nは8/16/32/64などのビット幅)。
| マクロ | 対象の型 |
|---|---|
SCNbN |
intN_t / uintN_t |
SCNbLEASTN |
int_leastN_t / uint_leastN_t |
SCNbFASTN |
int_fastN_t / uint_fastN_t |
SCNbMAX |
intmax_t / uintmax_t |
SCNbPTR |
intptr_t / uintptr_t |
例
#include <cinttypes>
#include <cstdint>
#include <cstdio>
int main()
{
std::uint16_t x = 0;
std::sscanf("1101", "%" SCNb16, &x); // "1101"を2進数として解釈する
std::printf("%d\n", x);
}
出力
13
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
PRIbN,PRIBN: 固定幅整数型を2進数として出力するための変換指定子
参照
- P3348R4 C++26 should refer to C23 not C17
- C++26がC23を参照するようになり、これらのマクロが
<cinttypes>に追加された
- C++26がC23を参照するようになり、これらのマクロが