What you did would turn all letters uppercase, one by one. I am really lost as what the if-clause would do in your code, but I suspect you should use == instead of =. My example works differently:
// define proper function somewhere
// and decide which characters are allowed as word separators
// ' ' (space) is one of them obviously.
bool isWordSeparator( char c ) ;
// ...
for(int a=0; a < phrase.length(); ++a)
{
if( a == 0 ) // first letter of a sentence
{
phrase.at(a) = toupper(phrase.at(a));
}
// check if preceding letter was word separator,
// which would imply this letter is first in a word.
// Be careful not to check a = 0-1 here, to avoid crash
elseif( isWordSeparator(phrase.at(a-1)) )
{
phrase.at(a) = toupper(phrase.at(a));
}
}
return phrase;