0
Plz explain me.... int d = s2.compare(s2.size() -1,1,s3,s3.size() -1,1);
#include <iostream> #include <string> using namespace std; int main() { string s1("Road"); string s2("Read"); string s3("Red"); int a = s1.compare(0,2,s2,0,2); int b = s2.compare(0,2,s1,0,2); int c = s2.compare(0,2,s3,0,2); int d = s2.compare(s2.size() -1,1,s3,s3.size() -1,1); cout<< "a ="<<a ; cout<<"\n"<<"b ="<<b<<"\n"; cout<<"c ="<<c<<"\n"; cout<<"d ="<<d; return 0; }
5 Respostas
+ 1
I would look up the compare function. quickly though.
line int a: s1 compared to s2 both starting at 0 for a length of 2
+ 1
size of s2 - 1. which equals 3.
do the math and those become the inserted values like above. (3,1,s3,2,1)
+ 1
they are equal as they are both "d"
do you understand now?
If the "letters" compared are the same return 0
if there is a difference it will return either 1 or -1 depending on the difference
a to b = 1
b to a = -1
0
can you explain me this line ?
int d=s2.compare(s2.size()-1,1,s3,s3.size()-1,1);
0
when we run this code, value of d is 0...how its possible?