c++程序—字符串

  1. C风格字符串:char 变量名[ ]="字符串值 "
int main()
{
    
    char str[] = "hello world!";
    cout << str << endl;


    system("pause");
    return 0;

}

  2. C++风格的字符串:string 变量名 = “字符串值”

  • NB:要加一个头文件:
    #include<string>
#include<iostream>
using namespace std;
#include<string>

int main()
{
    
    string str = "hello world!";
    cout << str << endl;
    system("pause");
    return 0;

}

 

posted @ 2020-02-25 08:50  Jackie_Wang  阅读(202)  评论(0编辑  收藏  举报