標題:
陣列 (三) - 宣告字串 2
[打印本頁]
作者:
陳品肇
時間:
2019-1-26 10:12
標題:
陣列 (三) - 宣告字串 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 11:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char n1[5]="kaka";
char n2[4]={'k','a','k','a'};
string n3[2]={"ka","ka"};
string n4="kaka";
int a=5;
char c='k';
cout<<n1<<endl;
for(int i=0; i<4; i++)
cout<<n2[i];
cout<<endl;
for(int i=0; i<2; i++)
cout<<n3[i];
cout<<endl;
cout<<n4<<endl;
cout<<a<<endl;
cout<<c<<endl;
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-1-26 11:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char f[4]="Ian";
char f2[3]={'I','a','n'};
string f3[2]={"Ia","n"};
string f4="Ian";
int a=3;
char c='X';
cout<<f<<endl;
for(int i=0;i<4;i++)
cout<<f2[i];
cout<<endl;
for(int i=0;i<2;i++)
cout<<f3[i];
cout<<endl;
cout<<f4<<endl;
cout<<a<<endl;
cout<<c<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蘇昱全
時間:
2019-1-26 11:21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char n1[5]="nick";
char n2[4]={'n','i','c','k'};
string n3[2]={"nic","k"};
string n4="nick";
int a=4;
char c='n';
cout<<n1<<endl;
for(int i=0; i<4; i++)
cout<<n2[i];
cout<<endl;
for(int i=0; i<2; i++)
cout<<n3[i];
cout<<endl;
cout<<n4<<endl;
cout<<a<<endl;
cout<<c<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2