现在的位置: 首页 > 综合 > 正文

字符串的三种存放方式

2012年06月22日 ⁄ 综合 ⁄ 共 289字 ⁄ 字号 评论关闭
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    //用字符串数组存放一个字符串
	char str1[] = "I am happy!";
	cout << str1 << endl;


	//用字符串变量存放字符串
	string str2 = "I am happy!";
	cout << str2 << endl;


	//用字符指针指向一个字符串
	char *str3 = "I am happy!";
	cout << str3 << endl;


	system("pause");
	return 0;
}

抱歉!评论已关闭.