




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、(2)一串字符的輸出用 cout 輸出字符數(shù)組#include <iostream>using namespace std; int main()char a10 = "Computer" cout<<a;return 0;Computer00a0a1a2a3a4a5a6a7a8a9用 cout 輸出字符數(shù)組#include <iostream>using namespace std; int main()char a8 = 'C', 'o', 'm', 'p', '
2、u', 't', 'e', 'r' ;cout<<a; return 0;Computera0a1a2a3a4a5a6a7用 cout 輸出字符數(shù)組#include <iostream> using namespace std; int main()char weekday711 = "Sunday", "Monday","Tuesday", "Wednesday", "Thursday", "Friday
3、", "Saturday" ;for (int i = 0; i < 7; i+)cout << weekdayi << endl; return 0;Sunday00000Monday00000Tuesday0000Wednesday00Thursday000Friday00000Saturday000用 cout 輸出字符數(shù)組#include <iostream>using namespace std; int main()int a8 = 1,2,3,4,5,6 ;cout<<a; return 0;(2
4、)一串字符的輸入方法一:直接用cin輸入字符串#include <iostream>using namespace std; int main()char str10;cout << "enter a sentence:" << endl; while (cin >> str)cout << str<<endl; return 0;方法二:用cin.get( )函數(shù)輸入n 有3個參數(shù)的get函數(shù)cin.get(ch, 10,'n');10-1個字符(包含空格),賦給指定的字符數(shù)組;uu
5、如果在10-1個字符之前,遇到指定的終止字; (如果第3個參數(shù)沒有指符n,則提前結(jié)束定,則默認為n返回非0值(真),如失敗(遇文件結(jié)束符)則返回0值(假)。u方法二:用cin.get( )函數(shù)輸入#include <iostream> using namespace std; int main()char ch20;cout << "enter a sentence:" << endl; cin.get(ch, 10, o); /指定終止符為o cout << ch << endl;return 0;方法三:用ci
6、n.getline( )函數(shù)輸入#include <iostream> using namespace std; int main()char ch20;cout << "enter a sentence:" << endl; cin.getline(ch, 10, o); /指定終止符為o cout << ch << endl;return 0;方法三:用cin.getline( )函數(shù)輸入n getline與get的區(qū)別u getline遇到終止標志字符時結(jié)束,緩沖區(qū)指針移到終止標志字符之后;u get遇到終止
7、字符是停止,指針不移動cin.get( )We are good friends.We are good friends.cin.getline( )方法三:用cin.getline( )函數(shù)輸入#include <iostream> using namespace std; int main()char weekday711; for (int i = 0; i < 7; i+)cin.getline(weekdayi, 11); for (int i = 0; i < 7; i+)cout << weekdayi << endl; retur
8、n 0;一個需要特別關(guān)注的程序#include<iostream> using namespace std; int main()char a1010; int n = 0;cin >> n;for (int i = 0; i < n; i+) cin.getline(ai, 10);for (int i = 0; i < n; i+) cout << ai << endl;return 0;Pass!#include<iostream> using namespace std; int main()char a1010; int n = 0;cin >> n;cin.get( );
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 數(shù)字氣味營銷系統(tǒng)接入?yún)f(xié)議
- 2025甘肅省建筑安全員知識題庫
- D2363-79(2019)國外國際標準
- 醫(yī)療技術(shù)入股合同范本
- 關(guān)于公司收款合同范本
- 加入小區(qū)保安合同范本
- 中國電網(wǎng)合同范本
- 賣房過戶定金合同范本
- 鄉(xiāng)鎮(zhèn)廉政合同范本
- 專利制合同范本
- 統(tǒng)編版五年級下冊道德與法治全冊優(yōu)秀課件
- 《教育管理學》課件
- 水平井套內(nèi)不動管柱滑套多段壓裂工藝技術(shù)全解課件
- 凈水設備技術(shù)參數(shù)要求
- 腦血管造影護理課件
- 被執(zhí)行人財產(chǎn)申報表
- 稱呼禮儀精品課件
- 課題申報講座課件
- 系統(tǒng)科學與系統(tǒng)工程的理論基礎
- 思想道德與法治課件:第四章 第二節(jié) 社會主義核心價值觀的顯著特征
- 四步創(chuàng)業(yè)法:創(chuàng)業(yè)必備知識點課件
評論
0/150
提交評論