C++ 字符串反转中的代码有什么问题?
在下面的代码中,我得到了下面提到的错误。请告诉我 为什么*p=t在这里给出错误C++ 字符串反转中的代码有什么问题?,c++,c,C++,C,在下面的代码中,我得到了下面提到的错误。请告诉我 为什么*p=t在这里给出错误 void reverse (char *p) { int length=strlen (p); int c=0, i=length/2; char *Temp=p+length-1, t; while (c<length) { t=*Temp; *Temp=*p *p=t; //Gives error as il
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}
void反向(char*p)
{
整数长度=strlen(p);
int c=0,i=长度/2;
字符*温度=p+长度-1,t;
(c缺少分号:
t=*Temp;
*Temp=*p ; //--here
*p=t;
由于C++中提到了C++,这里介绍如何使用STL:<代码> STD::String Retry=字符串(STR.RealEnter(),STR.Read())来反转字符串;