我整天都在做这件事,但没有运气。现在是晚上,不知道该怎么办。我的任务是读取用户输入句子中元音的数量、空格的数量和其他字符的数量。我知道我需要将 cin.get(ch) 用于空格,但不知道如何。我还需要将句子输出到文件中。继承人我到目前为止:
//Get data from user
cout << "Enter your sentence on one line followed by a # to end it: " << endl;
while (cin >> noskipws >> character && character != '#')
{
character = static_cast<char>(toupper(character));
if (character == 'A' || character == 'E' || character == 'I' ||
character == 'O' || character == 'U')
{
vowelCount++;
isVowel = true;
}
if (isspace(character))
{
whiteSpace++;
}
else if (isVowel == true && isspace(character))
{
otherChars++;
}
outFile << character;
}
outFile << "vowelCount: " << vowelCount << endl;
outFile << "whiteSpace: " << whiteSpace << endl;
outFile << "otherchars: " << otherChars << endl;