I am just getting started in C++.
I am trying to get the first three characters of the string 'str', and compare it to a known string, say, 'knownString'.
To do that, I wrote this line of code:
if (str.substr(start, 3) == knownString)
where 'start' is an integer I declared before. But I keep getting this warning message:
warning: implicit conversion changes signedness: 'int' to 'std::__cxx11::basic_string,** **std::allocator >::size_type' (aka 'unsigned int')
Does anyone knows what I can add or I missed in this statement to fix this?
You can:
Either 1. make the conversion explicit:
str.substr(static_cast<std::string::size_type>(start), 3)
Or 2. not make a conversion in the first place:
std::string::size_type start;
Or 3. ask compiler to not warn about it:
g++ compilation arguments -Wno-sign-conversion
I recommend option 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With