The size_t
values are being narrowed. In c++11, you could make this fail with an error by doing:
#include <string>
int main() {
std::string line;
int i{line.size()};
int j{line.length()};
}
The errors produced look like:
gh.cc:5:11: error: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [-Wc++11-narrowing]
int i{line.size()};
^~~~~~~~~~~
gh.cc:5:11: note: override this message by inserting an explicit cast
int i{line.size()};
^~~~~~~~~~~
static_cast<int>( )
gh.cc:6:11: error: non-constant-expression cannot be narrowed from type 'size_type' (aka 'unsigned long') to 'int' in initializer list [-Wc++11-narrowing]
int j{line.length()};
^~~~~~~~~~~~~
gh.cc:6:11: note: override this message by inserting an explicit cast
int j{line.length()};
^~~~~~~~~~~~~
static_cast<int>( )