#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; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter