当前位置:编程学习 > VC++ >>

vc++编辑问题

#include<iostream.h>
void main
{
 int a[5],int j=0,int i=0,int k;
 cout<<"输入:";
 cin>>a[0]<<a[1]<<a[2]<<a[3]<<a[4];
 for(i=5;i>0;i--)
  for(j=0;j<i;j++)
   if(a[j]>a[j+1])
   {
    k=a[j];
    a[j]=a[j+1];
    a[j+1]=k;
   }
   cout<<"输出:"<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;
}

问题错误

--------------------Configuration: test - Win32 Debug--------------------
Compiling...
tesg2.cpp
C:\删\MSDev98\MyProjects\test\tesg2.cpp(3) : error C2182: 'main' : illegal use of type 'void'
C:\删\MSDev98\MyProjects\test\tesg2.cpp(3) : error C2239: unexpected token '{' following declaration of 'main'
执行 cl.exe 时出错.

test.exe - 1 error(s), 0 warning(s)

追问:刚刚学 是个新手.......我的是VC++6.0编的
不对撒.....都纠结一个上午了   cin和cout是这么编的吧  我上次这么编 也没有显示是cin错误
答案:
我去,你连main函数也不会写?!
改成这样:
#include <iostream>
int main(){

}

#include<iostream.h>
void main
{
 int a[5],int j=0,int i=0,int k;
 cout<<"输入:";
 cin>>a[0]<<a[1]<<a[2]<<a[3]<<a[4];
 for(i=5;i>0;i--)
  for(j=0;j<i;j++)
   if(a[j]>a[j+1])
   {
    k=a[j];
    a[j]=a[j+1];
    a[j+1]=k;
   }
   cout<<"输出:"<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<" "<<a[4]<<endl;
}
在if外面添加一个中括号即可

上一个:vc++连接数据库
下一个:VC++指针编程

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,