注册 登录
编程论坛 VC++/MFC

哪位大神帮初学者看看啊

nbbgood 发布于 2011-11-04 19:13, 755 次点击
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
        for (char capital='A',char small='a';capital<='Z';capital++,small++)
        {
        cout<<"\t"<<capital<<hex<<setw(10)<<static_cast<int>(capital)<<dec<<setw(10)<<static_cast<int>(capital)<<endl;
   
        }
  return 0;
}
编译
1>------ Build started: Project: 36, Configuration: Debug Win32 ------
1>Build started 2011/11/4 18:50:57.
1>InitializeBuildStatus:
1>  Touching "Debug\36.unsuccessfulbuild".
1>ClCompile:
1>  hh.cpp
1>e:\vc程序\36\36\hh.cpp(6): error C2062: type 'char' unexpected
1>e:\vc程序\36\36\hh.cpp(6): warning C4552: '<=' : operator has no effect; expected operator with side-effect
1>e:\vc程序\36\36\hh.cpp(6): error C2065: 'small' : undeclared identifier
1>e:\vc程序\36\36\hh.cpp(6): error C2143: syntax error : missing ';' before ')'
1>e:\vc程序\36\36\hh.cpp(6): error C2143: syntax error : missing ';' before ')'
1>e:\vc程序\36\36\hh.cpp(7): error C2143: syntax error : missing ';' before '{'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.06
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
应该改哪里呀,我用的VC++2010
2 回复
#2
yuccn2011-11-04 20:32
for (char capital='A',char small='a';capital<='Z';capital++,small++)

这句话有两个要改的,
1、 char small='a' 前面的char要去掉
2、small 这个不可以用作变量,换成其他的名字吧,因为在rpcndr.h中有个#define small char

它被一个宏用去了

所以你的程序那句话改成

for (char capital='A',small_1='a';capital<='Z';capital++,small_1++)

就行了
#3
nbbgood2011-11-07 00:09
回复 2楼 yuccn
额,一不小心就不行了!!非常感谢啊!!
1