C++ C++;如何将字符串中每个句子/行的第一个单词大写?

C++ C++;如何将字符串中每个句子/行的第一个单词大写?,c++,string,line,capitalization,C++,String,Line,Capitalization,我现在正在脱发。我有一个字符串,我操纵它在标点符号后开始一个新行/句子,但我不明白如何将每个句子的第一个单词大写?除此之外,我无法跳出循环将点更改为点和新线 int main() { string const txt1 = "Candy is good for your health."; string const text2 = "All kids should buy candy."; string const text3 = "Candy nowadays is a

我现在正在脱发。我有一个字符串,我操纵它在标点符号后开始一个新行/句子,但我不明白如何将每个句子的第一个单词大写?除此之外,我无法跳出循环将点更改为点和新线

int main()
{
    string const txt1 = "Candy is good for your health.";
    string const text2 = "All kids should buy candy.";
    string const text3 = "Candy nowadays is a hit among kids.";
    string const text4 = "Every meal should include candy.";


    string text = text1 + text2 + text3 + text4;

    transform(text.begin(), text.end(), text.begin(), ::tolower);

    while (text.find("candy") != string::npos)
        text.replace(text.find("candy"), 3, "fruit");
    string_replace_all(text, ".", ".\n");
到目前为止,我已经补充了以下内容:

string line, total = ""; istringstream stream(text);
while (getline(stream, line, '\n'))
{
    if (line.size() > 0)
        total += (char)toupper(line[0]) + line.substr(1) + "\n";
    else total += "\n";
}

一个非常简单的方法是:

string line, total = ""; istringstream stream(someString);
while(getline(stream, line, '\n')) 
{
    if(line.size() > 0) 
        total += (char)toupper(line[0]) + line.substr(1) + "\n";
    else total+= "\n";
}

希望这能有所帮助。

@Thesar帮你完成了我的帖子吗?在我尝试@JakeFreeman之前,它被删除了。我现在就试试。还要确保在字符串之间插入
\n
字符。getline属于哪个库?我不能让它工作。错误:E0349没有运算符“+”与这些操作数匹配E0304没有重载函数“getline”的实例与参数列表匹配E0070不允许不完整类型(流)@JakeFreemanOk让我知道@Thesar