Capitalizing first letter in string array

I'm writing this code and I don't know how to capitalize the first letter of each string in the array. Does anyone know how to do this? Here is my attempt, this will only capitalize the first letter and display it, but not the full word.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
string arr[3]={"hello","cruel", "world"};

arr[0][0] = toupper(arr[0][0]);
cout << arr[0][0];

return 0;
}
You need a for loop, the size of your array.
1
2
for(int x = 0; x<3;x++)
  arr[x][0] = toupper(arr[x][0]);


Then a for loop to print the words. Leave off the [0], and just use [x], and the whole word will print.
Thank you, I really appreciate it.
Topic archived. No new replies allowed.