我在某处读到我需要安装“构建基本打包程序”,因此我尝试:
sudo apt-get install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
但该文件仍然无法编译或运行......
gcc -Wall -W -Werror factorial.cpp -o factorial.
给我:
gcc -Wall -W -Werror factorial.cpp -o factorial.
factorial.cpp:3:22: fatal error: iostream.h: No such file or directory
compilation terminated
这是我的一段代码://WAP 演示计算阶乘的静态成员
#include<iostream.h>
#include<conio.h>
class fact
{
int i;
static int count;
public :
void calculate()
{
long int fact1=1;
count++;
for(i=0;i<=count;i++)
{
fact1=fact1*i;
}
cout<<"\nFactorial of"<<count<<"="<<fact1<<"\n";
}
};
int fact :: count;
void main()
{
int i;
clrscr();
fact f;
for(i=1;i<=15;i++)
{
f.calculate();
}
getch();
}
我该怎么办..???
答案1
您的测试源包存在几个问题。
我的猜测是,您正在尝试使用稍旧的 C++ 标准(gcc
而不是g++
)进行编译,并且可能基于 Windows 例程(使用conio
)。
我为你整理了测试程序:
#include <iostream> /* dont need .h */
using namespace std; /* use a namespace */
/* #include <conio.h> this is a windows header - dont need */
class fact
{
int i;
static int count;
public :
void calculate()
{
long int fact1=1;
count++;
for (i = 2; i <= count; i++)
{
fact1 *= i;
}
cout << "\nFactorial of " << count << '=' << fact1 << '\n';
}
};
int fact :: count;
int main(void) /* you had an invalid main declaration */
{
int i;
/* clrscr(); not necessary */
fact f;
for (i = 1; i <= 15; i++)
{
f.calculate();
}
/* getch(); not necessary */
return 0; /* need to return a standard value */
}
然后使用编译
g++ factorial.cpp -o factorial
答案2
尝试:#include <iostream>
https://stackoverflow.com/questions/214230/iostream-vs-iostream-h-vs-iostream-h
答案3
尝试另一个只是为了测试,因为它说No such file or directory
。或者源文件可能已损坏。