Untitled
unknown
plain_text
3 years ago
524 B
14
Indexable
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string firstLetterToUppercase(string str) {
int n = str.length();
string result = "";
for (int i = 0; i < n; i++) {
if (i == 0 || str[i - 1] == ' ') {
result += toupper(str[i]);
}
else {
result += str[i];
}
}
return result;
}
int main() {
string str = "the quick brown fox jumps over the lazy dog";
cout << firstLetterToUppercase(str) << endl;
return 0;
}
Editor is loading...