c风格:
#include <iostream>
using namespace std;
int main()
{
char str[]="hello world";
cout << str << endl;
return 0;
}
c++风格:
注意:需新增头文件#include <string>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "hello world";
cout << a << endl;
return 0;
}
需要注意的一些事项:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name = "ABCDE";
for (int i = 0; i < 5; i++)
cout << name[i];
return 0;
}
输出ABCDE
输入(使用cin >>):
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "hello";
cin >> a;
cout << a << endl;
return 0;
}