这是我第一次用c++写的程序
编译时说有12个错误,可把我给打击坏了
请帮忙解决一下 大恩不言谢
#include <iostream.h> int & put(int n); int get (int n); int vals[10]; int error=-1; void main() { put(0)=10; put(1)=20; put(9)=30; cout<<get(0)<<endl; cout<<get(1)<<endl; cout<<get(9)<<endl; put(12)=1; } int& put(int n) { if(n>=10) { cout<<"range error in put() value!"<<endl; exit error;} return vals[n]; }
int get(int n) {if(n>=10) { cout<<"range error in get() value!"<<endl; exit error;} return vals[n]; }
下面是错误:
D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(2) : error C2059: syntax error : '&' D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(7) : warning C4013: 'put' undefined; assuming extern returning int D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(7) : error C2106: '=' : left operand must be l-value D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(8) : error C2106: '=' : left operand must be l-value D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(9) : error C2106: '=' : left operand must be l-value D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(10) : error C2065: 'cout' : undeclared identifier D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(10) : error C2297: '<<' : illegal, right operand has type 'char [3]' D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(11) : error C2065: 'endl' : undeclared identifier D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(11) : warning C4552: '<<' : operator has no effect; expected operator with side-effect D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(12) : warning C4552: '<<' : operator has no effect; expected operator with side-effect D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(13) : warning C4552: '<<' : operator has no effect; expected operator with side-effect D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(14) : error C2106: '=' : left operand must be l-value D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(16) : error C2059: syntax error : '&' D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(25) : error C2297: '<<' : illegal, right operand has type 'char [28]' D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(26) : error C2065: 'exit' : undeclared identifier D:\Program Files\Microsoft Visual Studio\Vc98\yinyong.c(26) : error C2146: syntax error : missing ';' before identifier 'error' Error executing cl.exe.
yinyong.obj - 12 error(s), 4 warning(s)