c++疑惑
# include <iostream.h># include <string.h>
template <class T>
T Max(T a,T b){
return (a>b)?a:b;
}
void main(){
int ix=12,iy=13;
double dx=9.9,dy=7.8;
string sx("abv"),sy("uid");
cout<<"Type int:"<<Max(ix,iy)<<endl;
cout<<"Type double:"<<Max(dx,dy)<<endl;
cout<<"Type string:"<<Max(sx,sy)<<endl;
}
以上是源程序,可是在编译时却出现以下错误:
Compiling...
temexample.cpp
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2065: 'string' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2146: syntax error : missing ';' before identifier 'sx'
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2065: 'sx' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2065: 'sy' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(14) : error C2065: 'cout' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(14) : error C2297: '<<' : illegal, right operand has type 'char [10]'
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(14) : error C2065: 'endl' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(15) : error C2297: '<<' : illegal, right operand has type 'char [13]'
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(16) : error C2297: '<<' : illegal, right operand has type 'char [13]'
执行 cl.exe 时出错.
First.exe - 1 error(s), 0 warning(s)
万望指教!