Заданный текст превратить таким образом, чтобы каждое слово начиналось с большой буквы. Считать, что слова текста разделены одним пробелом — C++(Си)

#include <iostream>
#include <string>
#include <sstream>
#include <cctype>
 
int main(){
    std::string buf;
    
    while ( true ){
        std::cout << "String: ";
        std::getline(std::cin, buf);
        if ( buf.empty() )
            break;
        std::istringstream ist(buf);
        std::ostringstream ost;
        while ( ist >> buf ){
            *buf.begin() = toupper(*buf.begin());
            ost << buf << ' ';
        }
        std::cout << "Result: " << ost.str() << std::endl;
    }
    
    return 0;
}

Leave a Comment