如何使用 getche() 计算短语的单词并忽略 C++ 中带有两个字符的单词
how to count a words of a phrase and ignore the words with two characters in c++ using getche()
我是 C++ 的新手,我在大学里有一个程序要求计算大小大于两个字符的单词和用户输入的短语中所有字符(忽略空格)的数量。程序使用头文件中的函数 getche() 逐个字符接受短语,直到按 Enter 键。与程序的交互可能如下所示:
输入文本:欢迎使用 C++ 字数为:2 字符数为:我停止了这一步,发现忽略两个字符的单词有问题,请帮忙...
#include <iostream>
#include<conio.h>
using namespace std;
int main(){
int chcount=0;
int wdcount=1;
int spccount=0;
char ch;
cout<<"Please,Enter a phrase :"<<endl;
while((ch=getche())!='r'){
if(ch!=' '){
chcount++;
}else if (ch==' '){
wdcount++;
}
}
cout<<"Count of words is : "<<wdcount<<endl;
cout<<"Count of Letters is : "<<chcount<<endl;
//cout<<"Count of space :"<<spccount<<endl;
return 0;
}
#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
int chcount = 0, wdcount =0, count = 0;
char ch='a';
cout << "Enter your text : ";
while ( ch != 'r' )
{
ch = getche();
if ( ch !=' ' )
{
chcount++;
count++;
}
else if (count > 2)
{
wdcount++;
count=0;
}
}
cout<<"nCount of words is: "<<wdcount+1<<"nCount of charcters is: "<<chcount-1<<"n";
system("pause");
return 0;}
顺便说一下,我是你的同事卡里姆·福阿德:)希望这有帮助
相关文章:
- 当您在此单词中搜索单词时调整字符数组的大小?
- 反转字符串中单词的位置,而不更改 O(1) 空格限制中特殊字符的顺序
- C ++程序在字符数组中插入单词
- C++ - 使用结构数据类型将单词中的单个小写字符更改为大写,反之亦然
- 延迟逐个字符打印单词
- 创建单词对齐的字符向量
- 在字符数组中存储和恢复一组单词
- 如何用单词排列向量中的每个字符升序?
- 如何在字符指针数组中保留指向每个单词的指针?
- 当找到来自 RHS 的字符"\"时,从主字符串中获取单词或子字符串,然后擦除其余部分
- 视觉C++查找以 "ing" 结尾且少于或等于 10 个字符的单词
- 需要将单词的文本文件存储到C 中的字符阵列中
- 从字符数组中删除单词
- 忽略给定单词之前的所有字符
- 如何计算C++字符数组中的单词
- 如何用新单词替换未知数量的相同字符
- (C++) 打印字符数组字符串的单词时出现问题
- 计数句子中单词的字符数
- 如何计算两个文件中字符单词和行的总数,并将它们相加以得出总数
- 我如何写一个Qt正则表达式来突出显示字符串开始和结束与非单词字符