用C++语言统计字符串中字符和单词的个数

2025-05-12 22:06:47
推荐回答(3个)
回答1:

#include
#include
#include
int main()
{
std::string::size_type lCount = 0, wCount = 0;
std::string str = "Avalon Excaliburn", word;
std::istringstream istr(str);
while (istr >> word) {
lCount += word.size();
++ wCount;
}
std::cout << str << "\n" << wCount << "\t" << lCount << std::endl;
system("pause>nul");
return 0;
}

回答2:

C语言字符串的学习,输入指定字符串,并且计算字符串的位数

回答3:

谭浩强的C语言程序设计有一个这样的例子