/*
字符串的基本用法主要是指字符串类对象的定义与初始化方法。
*/
#include <iostream>
int main(int argc,const char* argv[])
{
//在栈上定义了一个空的字符串对象:
std::string str
//在栈上定义了一个字符串对象,然后调用构造函数对其进行初始化
std::string str1("Hello world!");
//在堆中实例化字符串类,然后用字符串指针指向它
std::string *pstr = new std::string;
std::string *pstr1 = new std::string();
std::string *pstr2 = new std::string("Hello World!");
//将一个C语言的字符串直接赋值给一个C++的字符串
std::string str4 = "Hello World!";
//将一个字符指针或一个字符数组赋值给一个C++的字符串
char const *pc = "Hello World!";
std::string str5 = pc;
char sa[] = "Hello World!";
std::string str6 = sa;
/*
如果希望用字符指针指向C++的字符串,则需要调用字符串类中的c_str()函数,该函数能够返回字符串对象中锁存储的字符串数据在内存中的地址。
*/
char const *pc1 = str6.c_str();
return 0 ;
}