#include<iostream>
#include<algorithm>
#include<string>
usingnamespace std;
int main()
{
string s1("Hello");
transform(s1.begin(),s1.end(),s1.begin(),ptr_fun<int,int>(std::toupper));
cout<<s1;
string s2;
cout<<"Enter something....\n";
getline(cin,s2);
transform(s2.begin(),s2.end(),s2.begin(),ptr_fun<int,int>(std::toupper)); // <---
//What do the function parameters mean???
//Especially the 3rd parameter,s2.begin()
if(s2.compare(s1) == 0)
cout<<"The strings are same !!! \n";
else
cout<<"They are different strings !!! \n";
return 0;
}
The thing is I dont understand the parameters of std::transform(),I mean to say tht what they are used for.
Can anyone explain this to me pls??? Thnx in advance
result
Output iterator to the initial position of the range where the operation results are stored. The range includes as many elements as [first1,last1).
d_first - the beginning of the destination range, may be equal to first1 or first2
Specifically in your second call to transform, the third parameter equals the first, and transform is going to store each transformed element at the same position in the sequence where it read it from, that is, it's a transform in-place.
by the way,
if(s2.compare(s1) == 0)
if you don't need three-way compare, don't use it. It's "if(s1 == s2)"