toupper()
:#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
int main()
{
char str[100];
cout << "Enter a string: ";
cin.getline(str, 100);
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (islower(str[i])) {
str[i] = toupper(str[i]);
}
}
cout << "Uppercase string: " << str << endl;
return 0;
}
Enter a string: freetimelearning.com
Uppercase string: FREETIMELEARNING.COM
cin.getline()
. We then use a loop to iterate over each character in the string. If the character is lowercase
, we convert it to uppercase
using the toupper()
function. Finally, we print the uppercase
string to the console using cout
.