#include <iostream>
#include<string>
using std::string;
using namespace std;
int main()
{
string s("some string");
*s.begin() = toupper(*s.begin());
std::cout << s << std::endl;
}
And the result is:
Some string
Why *s.begin() have to be used ? Why I cannot just use s.begin() ? like:
s.begin() = toupper(s.begin());
Why the dereferencing operator * have to be used infront of an iterator ?
In the book C++ prime FIFTH EDITION P.107 , it said we dereference that iterator to pass that character to toupper and to return the upper letter S to the original string.
But still I don't get it, why we cannot use the s.begin() directly. Isn't pointer just to save memory ?