Download presentation
Presentation is loading. Please wait.
1
String Messy Details Unsigned vs signed
2
String Literals are not Strings
Other things (const char[] ) Chars
3
Unsigned vs Signed Unsigned integer : unsigned int
Plain binary ≈ 4 billion Signed (regular) integer : int Two's complement = -1
4
Comparing Signed & Unsigned
Weirdness:
5
Strings & Unsigned String namespace defines a type size_type:
string::size_type Used to specify size and locations in string string::size_type length(); string::size_type find(string); It is (usually) an unsigned int
6
So? strValue.find(str) works different in these cases:
7
So? strValue.find(str) works different in these cases: 4 billion -1
8
npos string::npos Constant for largest possible value for string::size_type Use to check for "not in string" if( strVar.find(str) == string::npos ) { //did not find str }
9
So what do I do? Use -1 Direct comparison with function is warning
10
So what do I do? Use string::npos
Value stored as int will cause warning
11
So what do I do? Use string::npos and store as unsigned int
No warnings
12
So what do I do? Use string::npos and store as size_type Super correct
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.