for loop for string (Turning the whole first word to uppercase )

PHOTO EMBED

Mon Dec 13 2021 11:06:15 GMT+0000 (Coordinated Universal Time)

Saved by @abzal_nurgazy #c++

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



int main()
{
	string str("helloWorld ");
	/*
	the for loop terminates at that very time when the condition is not met. 
	In our case for loop works until the whitespace is met or we go beyond str size
	decltype is the almost the same auto, find data type automatically of the expression!!!
	*/

	for (decltype(str.size()) i = 0; i != str.size() && !isspace(str[i]); i++)
	{
		str[i] = toupper(str[i]);
	}
	

	cout <<"The new string is " << str<< endl;
	return 0;
}
content_copyCOPY