天天看点

C++基础之字符串的简单使用

说明:C++中可以使用两种不同的风格表示字符串。

第一种风格:

#include <iostream>
using namespace std;

int main() 
{
	char str[] = "123abc";

	cout << str << endl;//输出123abc

	system("pause");

	return 0;
}
           

第二种风格:

#include <iostream>
using namespace std;
#include <string>

/*
必须添加#include <string>头文件才能正常使用字符串
*/
int main() 
{
	string str = "abc123";

	cout << str << endl;//输出abc123

	system("pause");

	return 0;
}
           

继续阅读