> For the complete documentation index, see [llms.txt](https://peiyafei.gitbook.io/c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://peiyafei.gitbook.io/c/1.2-shu-ju-lei-xing/2.6-zi-fu-chuan-xing.md).

# 2.6 字符串型

**作用**：用于表示一串字符

**两种风格**

1. **C风格字符串**： `char 变量名[] = "字符串值"`

示例：

```
int main() {

	char str1[] = "hello world";
	cout << str1 << endl;
    
	system("pause");

	return 0;
}
```

{% hint style="info" %}

> C风格的字符串要用双引号括起来
> {% endhint %}

1. &#x20;**C++风格字符串**： `string 变量名 = "字符串值"`

示例：

```
int main() {

	string str = "hello world";
	cout << str << endl;
	
	system("pause");

	return 0;
}

```

{% hint style="info" %}
C++风格字符串，需要加入头文件 #include\<string>
{% endhint %}
