string s;
bool b[] = {s=="", s==s.c_str(), s.c_str()==""};
sets
b[] = {true, true, false};
why is b[2]
false?
If A==B
and A==C
, should that not imply B==C
?
VLOOKUP returning incorrect resultsIf you omit to supply match type in a range_lookup argument of VLOOKUP then by default it searches for approximate match values, if it does not find exact match value. And if table_array is not sorted in ascending order by the first column, then VLOOKUP returns incorrect results.
Problem: The lookup value is not in the first column in the table_array argument. One constraint of VLOOKUP is that it can only look for values on the left-most column in the table array. If your lookup value is not in the first column of the array, you will see the #N/A error.
Translated in plain English, the formula instructs Excel to return True if Vlookup is true (i.e. equal to the specified value). If Vlookup is false (not equal to the specified value), the formula returns False.
Absolute references An absolute reference is designated in a formula by the addition of a dollar sign ($) before the column and row. If it precedes the column or row (but not both), it's known as a mixed reference. You will use the relative (A2) and absolute ($A$2) formats in most formulas.
In this expression
s.c_str()==""
there are compared two pointers (addresses). The first one is the pointer returned by s.c_str()
and the second one is the pointer to the first character (terminaring zero character) of the string literal ""
.
It is evident that the addresses are different (bear also in mind that the string literal has the static storage duration).
To get the expected result you should write instead
std::strcmp( s.c_str(), "" ) == 0
As for these two expressions
s==""
and
s==s.c_str()
then there are compared strings because the standard class std::string has overloaded operator == for the right operand.
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