79588817

Date: 2025-04-23 14:17:59
Score: 0.5
Natty:
Report link

As said at cppreference

After constructing and checking the sentry object, which may skip leading whitespace, first clears str with str.erase(), then reads characters from is and appends them to str as if by str.append(1, c), until one of the following conditions becomes true:

  • N characters are read, where N is is.width() if is.width() > 0, otherwise N is str.max_size(),
  • the end-of-file condition occurs in the stream is, or
  • std::isspace(c, is.getloc()) is true for the next character c in is (this whitespace character remains in the input stream).

Reading of an input stream when using operator >> interrupts on a space character, not a newline. This means that in fact, when reading "hi _ ", your cycle passes twice for "hi" and "_", so the second time condition evaluates to true.

If you want to read the whole line, consider using std::getline.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Smok1e