注册 登录
编程论坛 C++教室

编译错误!

lockhawk 发布于 2008-09-23 18:56, 589 次点击
#include "iostream.h"
#include "stdlib.h"
#include "math.h"
void star(int a);
int main()
{
    int n;
    cout<<"请输入星号的个数:";
    cin>>n;
    cout<<star(n)<<endl;
    return 0;
}
void star(int a)
{
    
    for(int i=0;i<a;i++)
    {
        cout<<'*';
    }
}


error C2679: binary '<<' :no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)

#include "stdlib.h"不是已经调用void了?
7 回复
#2
blueboy820062008-09-23 19:08
cout<<star(n)<<endl;
cout要求操作的对象要有返回值!
你那个star(n)是void类型的!
不能这样写!!!
#3
lockhawk2008-09-23 19:14
怪我~看书不仔细~
#4
r32154072008-09-23 19:17
我是新手啊
对star()函数的调用不用输出流  你直接改成   
int n;
cout<<请输入星号的个数:”;
cin>>n;
star(n);
return 0;//就好了
还有  cout<<"*"; 是   "不是'把
#5
r32154072008-09-23 19:19
。。。
哈哈 说错了
#6
blueboy820062008-09-23 19:50
#7
我是2008-09-23 22:45
include "iostream.h"

void star(int a);

void main()
{
    int n;
    cout<<"请输入星号的个数:";
    cin>>n;
    star(n);
      
}
void star(int a)
{
   
    for(int i=0;i<a;i++)
    {
        cout<<'*';
    }
}
我有个问题 为啥运行完毕之后 直接就退出程序 而不出现press any key to continue..... ???
#8
守鹤2008-09-24 01:06
回复 7# 我是 的帖子
在程序的结束后加上

getchar();
就可以了
1