changing elements in the string to a new one using reference &

PHOTO EMBED

Mon Dec 13 2021 09:35:05 GMT+0000 (Coordinated Universal Time)

Saved by @abzal_nurgazy #c++

#include <iostream>
#include <string>
using namespace std;
using std::string;

/*
Remember that a reference is just
another name for a given object. When we use a reference as our control variable,
that variable is bound to each element in the sequence in turn. Using the reference,
we can change the character to which the reference is bound.

*/

int main()
{
	string str("HeLLo World");
	
	
	for (auto &n : str)
	{
		if (isupper(n))
			n=tolower(n);
		else
			n = toupper(n);
	}
	cout <<"The new string is " << str<< endl;
	return 0;
}
content_copyCOPY