ITeye博客

如何更改字符串

J2EE大鸟 · 2014-04-22 14:22 · C语言 · C/C++ · 编程语言 · Markdown

在修改字符串时,我们需要将字符串指针的地址传入至函数中,如下:

 

void print(char *str, char **strAddr) {
	str++;
	cout << str << endl;
	*strAddr = str;
}

 

 

即改变指针指向的位置,调用过程如下所示:

char *a = "abcdefg";
print(a, &a);
cout << a << endl;

 

结果如下:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。