进口碎石生产线设备:请大家帮一下忙,这一个程序通不过编译的原因,C++的

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 19:10:49
#include<iostream.h>
#include<alloc.h>

void main()
{
int arraysize;
int * array;
cout<<"Please input a number of array elements:\n";
cin>>arraysize;

array=(int *)malloc(arraysize * sizeof(int));

for(int count=0;count<arraysize;count++)
array[count]=count*2;

for(int count=0;count<arraysize;count++)
cout<<array[count]<<" ";

cout<<endl;
}
如果有TC里编译是否可以通过,有人装TC吗?这一个程序是钱能的<<C++程序设计教程>>里的.

语句错误

/*****************
//原因:
//count重复定义
//头文件为#include<malloc.h>

代码如下:

#include<iostream.h>
#include<malloc.h>

void main()
{
int arraysize;
int * array;
cout<<"Please input a number of array elements:\n";
cin>>arraysize;

array=(int *)malloc(arraysize * sizeof(int));

for(int count=0;count<arraysize;count++)
array[count]=count*2;

for(count=0;count<arraysize;count++)
cout<<array[count]<<" ";

cout<<endl;
}

*******************/

#include<iostream>
#include<malloc.h>
using namespace std;

void main()
{
int arraysize;
int * array;
cout<<"Please input a number of array elements:\n";
cin>>arraysize;

array=(int *)malloc(arraysize * sizeof(int));

for(int count=0;count<arraysize;count++)
array[count]=count*2;

for(count=0;count<arraysize;count++)
cout<<array[count]<<" ";

cout<<endl;
}
这是我给改的!
你的头文件包含错误应该是<malloc.h>
同时你的count 变量定义了两次

在gcc里编译正常通过,这是由于不同编译器对C++标准支持程度不同造成的。

//既然是C++为什么不用new??

#include<iostream.h>

int main(int argc, char* argv[])
{

int arraysize;
int * array;
cout<<"Please input a number of array elements:\n";
cin>>arraysize;

array=new int [arraysize];

for(int count=0;count<arraysize;count++)
array[count]=count*2;

for( count=0;count<arraysize;count++)
cout<<array[count]<<" ";

cout<<endl;

return 0;
}