C++syntax error : 'string' 10
代码如下:#include<iostream.h>#include<typeinfo.h>template<typenameT>#include<string.h>voi...
代码如下:
#include <iostream.h>#include <typeinfo.h>template <typename T>#include <string.h>
void sort(T Array, int size){ char *test = NULL;
if ( typeid(Array) == typeid(test) ) { test = ( strcmp( (Array) , (Array + 1) <= 0) )?Array:Array+1; for (int i = 2;i < size;i++) { test = ( strcmp( test , (Array + i) <= 0) )?test:Array+i; } cout << "最小的是:" + test + << endl; }
else { double temp = 0.0; temp = ( *(Array) < *(Array + 1) ) ? *(Array) : *(Array + 1); for(int i=2;i<size;i++) { temp = ( temp < *(Array + i) ) ? temp : *(Array + i); }
cout << "最小的是:" + temp + << endl; }}
int main(void){ int a[10] = { 1,3,5,7,9}; double d[3] = {-1.1, -2.2, -3.3}; char* name[3] = {"linda","lelele","linlin"};
sort(a,10); sort(d,3); sort(name,3);
return 1;}
这个第一个错误怎么改?看不懂 展开
#include <iostream.h>#include <typeinfo.h>template <typename T>#include <string.h>
void sort(T Array, int size){ char *test = NULL;
if ( typeid(Array) == typeid(test) ) { test = ( strcmp( (Array) , (Array + 1) <= 0) )?Array:Array+1; for (int i = 2;i < size;i++) { test = ( strcmp( test , (Array + i) <= 0) )?test:Array+i; } cout << "最小的是:" + test + << endl; }
else { double temp = 0.0; temp = ( *(Array) < *(Array + 1) ) ? *(Array) : *(Array + 1); for(int i=2;i<size;i++) { temp = ( temp < *(Array + i) ) ? temp : *(Array + i); }
cout << "最小的是:" + temp + << endl; }}
int main(void){ int a[10] = { 1,3,5,7,9}; double d[3] = {-1.1, -2.2, -3.3}; char* name[3] = {"linda","lelele","linlin"};
sort(a,10); sort(d,3); sort(name,3);
return 1;}
这个第一个错误怎么改?看不懂 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询