C++字符串型

135 阅读1分钟
#include<iostream>
using namespace std;

/*
字符串型
作用:用于表示一串字符
两种风格:
1. C风格字符串:char 变量名[] = "字符串值"
2. C++风格字符串: string 变量名 = "字符串值"
*/

int main(){
    
    //1. C风格字符串,注意:char 字符串名 [] ; 等号后面用双引号包含起来字符串
    char str[] = "hello world";
    cout << str << endl;

    //2. C++风格字符串, 注意:需要包含一个头文件 #include <string>
    string str2 = "hello world";
    cout << str2 << endl;
    
    system("pause");
    return 0;
}