c++ STL string 简单用法

前言

c++ STL string 简单用法

Code

#include
#include

using namespace std;

int main(){

    cout << "输出单个字符串" << endl;
    string str1 = "hello cpp!";
    for(int i=0; i < str1.size();i++){
        cout << str1[i] ;
    }
    cout << endl;

    cout << "输出字符串数组" << endl;
    string str2[10];
    for(int i=0;i < 10;i++){
        str2[i] = "loading ... ";
        cout << str2[i] << i <<endl;
    }

    return 0;
}

result

输出单个字符串
hello cpp!
输出字符串数组
loading ... 0
loading ... 1
loading ... 2
loading ... 3
loading ... 4
loading ... 5
loading ... 6
loading ... 7
loading ... 8
loading ... 9

你可能感兴趣的:(C++基础学习,c++,算法,开发语言)