我写了一个MyStrcpy函数,具体如下:
#include <iostream>
using namespace std;
void MyStrcpy(char *s2, char *s1)
{
while(*s1)
{
*s2 = *s1;
s2++;
s1++;
}
*s2 = '\0';
}
int main()
{
char s1[] = "12345678";
char s2[8] ={0};
MyStrcpy(s2, s1);
cout << s2 << endl;
return 0;
}
但是如果改成
#include <iostream>
using namespace std;
int main()
{
char s1[] = "12345678";
char s2[8] ={0};
while(*s1)
{
*s2 = *s1;
s2++;
s1++;
}
*s2 = '\0';
cout << s2 << endl;
return 0;
}
会报错:错误为error C2105: '++' needs l-value
当然s2输出也不对,求教原因.
临摹微笑