I was looking for a way to capitalize first letter of each word in a sentence using boost. To make the code consistent i.e the final output will not have any space or tab if present in the input sentence. To get individual words I m using boost::alogrithm::split and for combining them back boost::algorithm::join . but how do I get each first letter capitalized ?
我尝试了这部法律。
#include <iostream>
#include <vector>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>
int main()
{
using namespace std;
string str("cONtainS SoMe CApiTaL WORDS");
vector<string> strVec;
using boost::is_any_of;
using boost::algorithm::token_compress_on;
boost::algorithm::split(strVec, str, is_any_of(" "), token_compress_on);
vector<string>::iterator i ;
for(i = strVec.begin() ; i != strVec.end(); i++)
{
(*i)[0] = boost::to_upper((*i)[0]);
cout<<*i<<endl;
}
return 0;
}