I want to use toupper on each char after point . in the string.
I tried this code but I an getting a black screen when I start the program if I use + operator.
string fulltext = "my name is John. i have a girlfriend. her name is Anna";
string::size_type idx = 0;
while ((idx = fulltext.find(".")) != string::npos)
{
if (idx != string::npos)
{
fulltext[idx + 2] = toupper(fulltext[idx + 2]);
}
}
cout << fulltext << endl;
So it turns out that the only standard defined way to use
toupperis to pass anunsigned char: https://stackoverflow.com/a/37593205/2642059 Thus, the best way to do this is with a lambda in atransform, for example you could capitalizestring fulltextin it's entirety like this:Since you want to start at the first
'.'andtransformworks oniterators you could just usefindto obtain aniteratorto the'.'and use it in the 1st and 3rd arguments oftransform:auto it = find(begin(fulltext), end(fulltext), '.')But we can avoid the temporary if we do reverse iteration:Live Example