---
title: "如何更改字符串"
author: "J2EE大鸟"
date: "2014-04-22T14:22:13Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2014-04-22T14:22:13Z"
id: 2051831
url: "https://benworld.iteye.com/blog/2051831"
---

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

 

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

 

 

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

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

 

结果如下：

![](http://dl2.iteye.com/upload/attachment/0096/3696/f75dd8f7-938a-3267-b634-0d585d8bf0f3.png)