没有从我的字母计数程序中得到任何输出
not getting any output from my letter count program
我正在开发一个计算文本中字母数的程序,我似乎无法使其工作。有人能指出我做错了什么吗。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string inputxt;
cout << "enter txt:n";
getline(cin, inputxt);
char charcheck[ ]={'a', 'b', 'c', 'd'};
int charsize=sizeof(charcheck)/sizeof(char);
int count[charsize];
cout << charsize;
for (int i=0; i==inputxt.length(); i++){
for(int a=0; a==charsize; a++){
if (inputxt[i]==charcheck[a])
++count[a];
}
}
for (int b=0; b==charsize; b++){
cout << "number of " << charcheck[charsize] << ": " << count[charsize];
cout << endl;
}
return 0;
}
请注意,我没有输入所有字符来对照文本。谢谢
for (int i=0; i==inputxt.length(); i++){
for
构造采用3个参数:
- 初始化
- 继续条件(而不是像您那样的终止条件)。将其读取为
while ...
- 循环动作(又称事后思考)
换句话说,for (INIT; CONTINUATION; AFTERTHOUGHT) { BODY }
直接翻译为:
INIT;
while (CONTINUATION) { BODY; AFTERTHOUGHT; }
反转你的中间条件,它应该是i!=inputxt.length()
。这同样适用于每隔一个for
循环。
在for
循环中,使用的是==
而不是<
。例如:
for (int i=0; i==inputxt.length(); i++)
应该是:
for (int i=0; i < inputxt.length(); i++)
相关文章:
- 如何从Windows应用程序输出到标准?
- 在由Sublime文本3编译后在cmd上显示Java程序输出
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 而循环:简单的除法程序输出零,不明白为什么
- Qt creator 4.11,在应用程序输出面板中创建一个链接
- 使用复制构造函数的程序输出错误
- 为什么Qt Creator的应用程序输出不能从spdlog记录器打印
- 为什么在 Direct X 11 中没有我的程序输出?
- 我怎样才能阻止我的程序输出时间,它使我的程序难以阅读
- 程序输出奇怪的字符
- 程序输出"nan"
- 为什么我的C++程序输出不同的数字来将米转换为英尺?
- 3D 纹理大小会影响程序输出,而不会引发错误
- C++,程序输出无效输入,但继续通过循环
- 如何连接C++和Excel(从C++程序输出到Excel电子表格)
- 为什么我的C 程序输出乱码代码
- QT小部件应用程序输出到控制台
- 混淆了具有虚拟继承的程序输出
- 为什么我的C++程序输出这个
- 为什么我的程序输出不断变化?EAX寄存器不断更改值