字符数组

#include <iostream>
using namespace std;


int main(){
    //C++当中字符数组赋值,''单引号中不能为空 
    char talk[10]={'G','o',' ','p','a','l','y','e','r','!'};
    for(int i=0;i<10;i++){
        cout<<talk[i];
    }
    cout<<endl;
}

#include <iostream>
using namespace std;


int main(){
    //C++当中字符数组赋值,''单引号中不能为空 
    char talk[5][5]={{' ',' ','*'},
                    {' ','*',' ',' ','*'},
                    {'*',' ',' ',' ','*'},
                    {' ','*',' ','*'},
                    {' ',' ','*'}};
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++)
            cout<<talk[i][j];
            cout<<endl;
    }
    cout<<endl;
}

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


int main(){
    //C++当中字符数组赋值,''单引号中不能为空 
    char str1[30]="People's Republic of ";
    char str2[]="China";
    cout<<strcat(str1,str2);

}

原文地址:https://www.cnblogs.com/aipopo/p/7903437.html