编译时出现的问题如下图:
出错代码如下:
#include <iostream>
#include <string>
using namespace std;
//变量声明
extern int a,b;
extern int c;
extern float f;
#define LENGTH 10;
#define WIDTH 5;
#define NEWLINE '\n'
class Myclass{
public:
static int class_var;//类作用域变量
};
int Myclass::class_var=30;
int main()
{
int area;
area= LENGTH * WIDTH;
cout << area;
cout << NEWLINE;
//string greeting = "Hello,runoob";
//cout << greeting;
//cout << "\n";
//string greeting2="hello";
//cout <<greeting;
//cout << "类变量:" << Myclass::class_var <<endl;
变量定义
//int a,b;
//int c;
//float f;
实际初始化
//a=10;
//b=20;
//c=a+b;
//cout << c <<endl;
//f=70.0/3.0;
//cout << f <<endl;
return 0;
}
出错原因:#define语句后面加了 ; ,去掉分号就没问题了。