scnlib icon indicating copy to clipboard operation
scnlib copied to clipboard

Document or fix interaction of scn::prompt and result range()

Open dancingbug opened this issue 3 years ago • 2 comments

Hi. Modifying the first example given in the README, I have:

#include <scn/scn.h>
#include <cstdio>

int main() {
    int i, j;
    // Read an integer from stdin
    // with an accompanying message
    auto res = scn::prompt("What's your favorite number? ", "{}", i);
    scn::scan(res.range(), "{}", j);
    printf("Oh, cool, %d!\n", i);
    printf("Oh, even cooler, %d!\n", j);
}
// Example invocation:
// What's your favorite number? 345 6789
// Oh, cool, 345!
// Oh, even cooler, 9!

My "678" got eaten unexpectedly! Please make scnlib give it back, or if this is expected, document obviously the behavior of using range() to scan leftover input from different possible types.

I am using version 1.1

dancingbug avatar Mar 15 '22 13:03 dancingbug

The file handling stuff is a little iffy and hard to test when using stdin, but this definitely should have been caught. I'll look into this.

eliaskosunen avatar Mar 15 '22 20:03 eliaskosunen

Temporary fix in v1.1.1, the snippet in your message now works.

Keeping the issue open for a more substantial fix, including design changes.

eliaskosunen avatar Mar 16 '22 12:03 eliaskosunen