If you know that the string is at least one character long, the easiest way to capitalize the first letter of it is
Code:
str[0] = toupper(str[0]);
Now, to capitalize a whole string, there are two general approaches. One is to use Boost:
Code:
#include <boost/algorithm/string/case_conv.hpp>
to_upper(str);
The other is to capitalize each character individually. There are several methods here.
Code:
for(std::string::iterator it = str.begin(); it != str.end(); ++it) {
*it = toupper(*it);
}
Code:
std::transform(str.begin(), str.end(), str.begin(), toupper);
...
Take your pick. The Boost method is definitely the most elegant, but you're probably not allowed to use external libraries.