標題:
陣列 (三) - 宣告字串 2
[打印本頁]
作者:
陳品肇
時間:
2019-1-26 11:03
標題:
陣列 (三) - 宣告字串 2
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char n1[5]="Tony"; //字元陣列
char n2[4]={'T','o','n','y'}; //字元陣列
string n3[2]={"To","ny"}; //字串陣列
string n4="Tony"; //字串型態的變數
int a=3; //整數型態的變數
char c='P'; //字元型態的變數
cout<<n1<<endl; //輸出n1
for(int i=0; i<4; i++) //輸出n2
cout<<n2[i];
cout<<endl;
for(int i=0; i<2; i++) //輸出n3
cout<<n3[i];
cout<<endl;
cout<<n4<<endl; //輸出n4
cout<<a<<endl; //輸出a
cout<<c<<endl; //輸出c
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2019-1-26 14:27
本帖最後由 陳品肇 於 2019-1-26 14:30 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char a[7]="cheney";
char b[6]={'c','h','e','n','e','y'};
string c[2]={"che","ney"};
string d="cheney";
int e=3;
char f='p';
cout<<a<<endl;
for(int i=0;i<=5;i++)
{cout<<b[i];
}
cout<<endl;
cout<<c[0]<<c[1]<<endl;
cout<<d<<endl;
cout<<e<<endl;
cout<<f<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳孟修
時間:
2019-1-26 14:32
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char a1[4]="abc";
char a2[3]={'a','b','c'};
string b1="abc";
string b2[2]={"ab","c"};
int a=1;
char c='x';
cout<<a1<<endl;
for(int i=0;i<=3;i++)
{
cout<<a2[i];
}
cout<<endl;
cout<<b1<<endl;
for(int i=0;i<3;i++)
{
cout<<b2[i];
}
cout<<endl;
cout<<a<<endl;
cout<<c<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2019-1-26 14:40
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char a1[10]="Minecraft";
char a2[9]={'M','i','n','e','c','r','a','f','t'};
string b1[2]={"Mine","craft"};
string b2="Minecraft";
int c1=1;
char c2='2';
cout<<a1<<endl;
for(int i=0;i<9;i++)
{
cout<<a2[i];
}
cout<<endl;
for(int i=0;i<2;i++)
{
cout<<b1[i];
}
cout<<endl;
cout<<b2<<endl;
cout<<c1<<endl;
cout<<c2<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪寬瀧
時間:
2019-2-2 13:10
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char j1[7]="edward";
char j2[7]={'e','d','w','a','r','d'};
string j3[3]={"ed","wa","rd"};
string j4="edward";
int i=3;
char c='p';
cout<<j1<<endl;
for(int i=0; i<3; i++)
cout<<j3[i]<<endl;
cout<<endl;
cout<<j4<<endl;
cout<<c<<endl;
system("pause");
return 0;
}
複製代碼
作者:
章幼莛
時間:
2019-2-2 13:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char f[5]="章魚";
cout<<f<<endl;
char f1[5]={'S','a','b','e','r'};
for(int i=0;i<5;i++)
{
cout<<f1[i];
}
cout<<endl;
char y='I';
cout<<y<<endl;
string g[5]={"A","r","t","h","ur"};
for(int i=0;i<5;i++)
{
cout<<g[i];
}
cout<<endl;
string g1="Arthur";
cout<<g1<<endl;
int x=16;
cout<<x<<endl;
int x1[3]={1,2,3};
for(int i=0;i<3;i++)
{
cout<<x1[i]<<endl;
}
system("pause");
return 0;
}
複製代碼
回復
1#
陳品肇
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2