#include <cstdio>
#include <cstdint>
#include <cassert>
int main() {
std::uint64_t ui;
char c;
auto ret = std::sscanf("111K", "%lu64%[B, K, M, G]", &ui, &c);
assert(ret == 2);
assert(ui == 111);
}
I tried to use sscanf to read a uint64_t and a char from one string, but it only read it ui (assertion ret == 2 fails) every time I tried this.
You have two issues here. First
should be
to read in a 64 bit integer.
The second issue is
requires a
char*orwchar_t*as its output parameter as it populates a c-string. You need to changeto at least
in order capture
K. We put that all together and we getDo note that
is actually trying to match all of the spaces and comma inside the brackets. You could also write it as
and get the same results.