如下程序编译问题,是什么原因造成的错误,该怎么解决?
#include "stdafx.h"
#include <iostream>
using namespace std;
#ifdef __cplusplus
cout << "c++" << endl; //这里一定要有输出语句的。
#else
cout << "c" << endl; //这里一定要有输出语句的。
#endif
int main()
{
return 0;
}
编译提示如下:
--------------------Configuration: 2 - Win32 Debug--------------------
Compiling...
2.cpp
F:\VC工程\2\2.cpp(11) : error C2143: syntax error : missing ';' before '<<'
F:\VC工程\2\2.cpp(11) : error C2501: 'cout' : missing storage-class or type specifiers
F:\VC工程\2\2.cpp(11) : error C2143: syntax error : missing ';' before '<<'
Error executing cl.exe.
2.exe - 3 error(s), 0 warning(s)
[解决办法]
你把cout放主函数外什么意思?你认为有全局的cout和cin么?
[解决办法]
#ifdef __cplusplus
cout << "c++" << endl; //这里一定要有输出语句的。
#else
cout << "c" << endl; //这里一定要有输出语句的。
#endif
这些不过是条件编译而已,真正有效的是cout << "c++" << endl;或cout << "c" << endl;
这是普通的语句而已,当然要写在函数体里面了
[解决办法]
语句是不能放到函数外面的,是不会执行的。
[解决办法]