麻烦给看一下这个c++程序哪个地方出错了???????

来源:百度知道 编辑:UC知道 时间:2024/06/07 23:03:56
#include<stdafx.h>
#include<iostream>

using namespace std;

int main()
{
char ch;
int count=0; //最好初始化,否则会有警告
//int delay;

cout<<"Enter the character:!!!"<<endl;
cin.get(ch);
while(ch != '#')
{
cout<<ch;
count++;
cin.get(ch);
}
cout<<endl<<count<<" charaters read\n";
// cin>>delay;
return 0;
}

每次输入类似“jfdskjflksdjf#fdkslafjlksd”只要带有#符号的字符时,最后几句代码都是不执行.................
改进后的程序:
#include<stdafx.h>
#include<iostream>
int main()
{
using namespace std;
char ch;
int count=0;

cout<<"Enter characters:enter the # to quit;\n";
cin.get(ch);
while(ch !='#')
{<

while(ch != '#')
{
}
这儿的意思就是当遇到‘#’时就停止啊

第一句执行了,但程序退出了,第二句被注释了,不执行
把这两句的斜杠去掉即可
//int delay;
// cin>>delay

没问题啊,遇到“#”就结束输入,每行代码都执行了啊~~~