VisualStudio2008 C++编程,调试窗口自动关闭

//Ex3_01.cpp
//A need if demonstration
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char letter=0;//store input here

cout<<endl
<<"Enter a letter:";
cin>>letter;
if (letter>='A')
if(letter<='Z')
{
cout<<endl
<<"You entered a capital letter."
<<endl;
return 0;
}
if(letter>='a')
if(letter<='z')
{
cout<<endl
<<"You entered a small letter."
<<endl;
return 0;
}
cout<<endl<<"You didn't enter a letter."<<endl;
{
getchar();
}
return 0;

}
//无法暂停,看不出结果
输入字母后不停,而且把getchar();换成system("pause")也没用

程序不会执行到getchar();部分,因为你前面有return语句,前面的return语句删了吧~
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char letter=0;//store input here

cout<<endl
<<"Enter a letter:";
cin>>letter;
if (letter>='A' || letter<='Z')
{
cout<<endl
<<"You entered a capital letter."
<<endl;
}
else if(letter>='a' || letter<='z')
{
cout<<endl
<<"You entered a small letter."
<<endl;
}
cout<<endl<<"You didn't enter a letter."<<endl;
{
getchar();
}
return 0;
}追问

这个程序是判断大小写字母的,我输入一个字母后还是自动退出,除了输入两个getchar();以外还有别的办法吗?

追答

就用system("pause");啊,不行?
不好意思哈,上面的程序我写错了,刚刚注意到,|| 改成 &&!,疏忽了....

追问

我这个是VisualStudio2008中的C++,||没错,如果换成 &&!e:\c++\我的实例\ex3_01\ex3_01\ex3_01.cpp(12) : error C2065: “!”: 未声明的标识符
1>e:\c++\我的实例\ex3_01\ex3_01\ex3_01.cpp(12) : error C2146: 语法错误 : 缺少“)”(在标识符“letter”的前面)
……由于篇幅写不下很多错误,system("pause");完全没有效果,输入N个getchar();就能输入N-1个字母,不能让程序只按esc退出吗?谢谢

追答

编译器的问题...老实说,我现在也正在用VS2008,刚换的,VS2008编译器和以前其他编译器,都有很大的区别,这个你只有上网百度哈。我也没用惯,VC6.0换过来的,真的很不习惯,抱歉,这个问题我也帮不上你了。

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答