1 #include<iostream> 2 using namespace std; 3 int main(){ 4 char str[]="やはり俺の青春ラブコメは間違い"; 5 cout<<str<<endl; 6 int a[8]={1,864,89,46,48,35,24}; 7 for(int i=0;i<8;i++){ 8 cout<<a[i]<<endl; 9 } 10 }
定义一个字符串变量并初始化,输出
#include<iostream> using namespace std; int main(){ string str="asd nsn dao"; cout<<str<<endl; }
指向字符串的字符指针
#include<iostream> using namespace std; int main(){ char *str="asd nsn dao"; cout<<str<<endl; }
#include<iostream> #include <string.h> using namespace std; int main(){ char str[]="asd nsn dao"; char str2[]={9,8,24}; strcpy(str2,str); cout<<str2<<endl; }