IO

Similar documents
C/C++ - 文件IO

02

C/C++语言 - C/C++数据

新版 明解C++入門編

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

第八﹑九章 I/O系統

ebook55-13

C/C++程序设计 - 字符串与格式化输入/输出

プログラムの設計と実現II

Microsoft PowerPoint - CPP-Ch Print.ppt [兼容模式]

FY.DOC

新・解きながら学ぶC言語

_汪_文前新ok[3.1].doc

新版 明解C言語入門編

新・明解C言語入門編『索引』

untitled

c_cpp

先生別耍我

untitled

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

C/C++ - 字符输入输出和字符确认

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

CC213

C

上海交通大学

untitled

第3章.doc

ebook39-5

untitled

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

Microsoft Word - CPE考生使用手冊 docx

Microsoft Word - chap13.doc

epub 33-8

C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

提问袁小兵:

09 (File Processes) (mkdir) 9-3 (createnewfile) 9-4 (write) 9-5 (read) 9-6 (deletefile) 9-7 (deletedir) (Exercises)

C/C++ - 函数

Microsoft PowerPoint - ch12.ppt

NethersoleJO89(8).indd

PowerPoint Presentation

untitled

C语言的应用.PDF


迅速在两个含有大量数据的文件中寻找相同的数据

新・解きながら学ぶJava

extend

模 组 导 入 2013 年 冬 的 普 通 清 晨 探 索 者 在 准 备 去 上 学 或 者 上 班 的 时 候, 突 然 间 门 铃 响 了 走 出 玄 关 后 并 没 有 看 到 任 何 人, 只 有 一 张 票 夹 在 了 邮 箱 或 收 信 的 地 方 那 上 面 写 着 天 花 蔷 薇

C++ 程序设计 OJ9 - 参考答案 MASTER 2019 年 6 月 7 日 1

C/C++ - 字符串与字符串函数

untitled

Chapter12 Derived Classes

全国计算机技术与软件专业技术资格(水平)考试

《计算概论》课程 第十九讲 C 程序设计语言应用

untitled

untitled

E11701


秘密

Microsoft Word 軟體設計第二部份範例試題_C++_ _1_.doc

C 1

C C

C++ 程序设计 实验 2 - 参考答案 MASTER 2017 年 5 月 21 日 1

第十一章 流类库与输入/输出

<4D F736F F D20B2C43032B3B920B8EAAEC6ABACBA41BB50AAEDA5DCA6A12E646F63>

第一章.FIT)

大 綱 最 有 利 標 目 的 及 類 型 最 有 利 標 之 辦 理 方 式 準 用 最 有 利 標 取 最 有 利 標 精 神 最 有 利 標 之 類 型 及 其 相 關 規 定 適 用 最 有 利 標 準 用 最 有 利 標 及 取 最 有 利 標 精 神 作 業 程 序 及 實 務 分 析

3.1 num = 3 ch = 'C' 2

nooog

Microsoft PowerPoint - 20-string-s.pptx

概述

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

科学计算的语言-FORTRAN95

硕士论文正文

数据结构与算法 - Python基础

JavaIO.PDF

(6) 要 求 付 款 管 理 员 从 预 订 表 中 查 询 距 预 订 的 会 议 时 间 两 周 内 的 预 定, 根 据 客 户 记 录 给 满 足 条 件 的 客 户 发 送 支 付 余 款 要 求 (7) 支 付 余 款 管 理 员 收 到 客 户 余 款 支 付 的 通 知 后, 检

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

内 容 提 要 指 针 持 久 动 态 内 存 分 配 字 符 串 ( 字 符 数 组 ) 2

(➂)11. 炎 炎 夏 日, 即 使 下 起 滂 沱 大 雨, 都 消 除 不 了 令 人 心 煩 的 暑 氣 這 句 話 主 要 想 表 達 什 麼? ➀ 夏 日 裡 經 常 下 著 滂 沱 大 雨, 令 人 心 煩 ➁ 下 著 滂 沱 大 雨 的 日 子, 可 以 消 除 暑 氣 ➂ 夏 日

範本檔

高雄市立五福國民中學九十四學年度第一學期第三次段考二年級本國語文學習領域試題卷

人 物 春 秋 杨 永 泰 将 其 削 藩 策 略 概 括 为 : 以 经 济 方 法 瓦 解 冯 玉 祥 的 第 二 集 团 军, 以 政 治 方 法 解 决 阎 锡 山 的 第 3 集 团 军, 以 军 事 方 法 解 决 李 宗 仁 的 第 四 集 团 军, 以 外 交 方 法 对 付 张 学

台北老爺校外實地參訪結案報告


糖尿病食譜




Microsoft Word 養生與保健_中山大學_講義


萬里社區老人健康照護手冊

Microsoft Word - 強制汽車責任保險承保及理賠作業處理辦法 doc

Microsoft Word - 06.Understanding of Pregnancy and Birth.doc

附 件 一 : 办 理 集 中 式 银 期 转 账 业 务 网 点 名 单 序 号 地 区 网 点 名 称 地 址 联 系 人 电 话 23 工 商 银 行 安 徽 省 铜 陵 百 大 支 行 铜 陵 市 长 江 东 路 50 号 鲁 桂 珍 工 商 银 行 安 徽

2. 二 年 級 吳 毓 秀 老 師 : 感 謝 午 餐 公 司 平 時 均 能 準 時 送 餐, 但 希 望 能 不 要 使 用 加 工 品, 且 學 生 反 映 希 望 能 多 加 蛋 品 的 食 物 3. 三 年 級 柯 阿 青 老 師 : 雞 肉 有 血 水 味, 請 午 餐 公 司 能 調

,,,,,,, (,, ),,,,,,,,,,,,,,, ,,, 4 11,, ( ),,,, ( ), :, ( ),,, 1995, 66 ; ( ),, 1996, , 3-4,,

2002 4,,, 1941,,,,,,,,,,,,,,,,,, : ;:, 1991,

Strings

Transcription:

1 C/C++ C FILE* fscanf fgets fread fprintf fputs fwrite C++ ifstream ofstream >> << 2 1

(iostream) ios: istream: ostream: ifstream: ofstream: fstream: 3 C++ ios istream ostream iostream ifstream fstream ofstream 4 2

cin : istream cout : ostream cerr : ostream clog : ostream 5 ios (flag) ios (flag) ios setf() unsetf() ios:: skipws left right dec oct hex showbase upercase showpos scientific fixed 6 3

ios #include <iostream.h> void main(){ cout<<12345.6<<endl; // 1.23456E+04 cout.setf(ios::hex); cout.setf(ios::fixed); cout<< 100<<endl; // 64 cout<<12345.6<<endl; cout.setf(ios::showbase); // 12345.6 cout << 100<<endl; // 0x64 cout.setf(ios::uppercase); cout << 255<<endl; // 0XFF cout.unsetf(ios::hex); cout.setf(ios::showpos); cout<<100<<endl; // +100 cout.setf(ios::scientific); 7 ios ws dec oct hex endl ends flush setw(int) setfill(int) setprecision(int) setiosflags(long) resetiosflags(long) #include <iomanip.h> 8 4

ios #include <iomanip.h> 12 void main(){ Computer cout<<setw(5)<<12<<endl; *******Computer cout<<setw(15)<<"computer"<<endl; 3.142 cout<<setfill('*'); 64 144 cout<<setw(15)<<"computer"<<endl; cout<<setprecision(3)<<3.1415926535<<endl; cout<<hex<<100<<endl; cout<<oct<<100<<endl; 9 ios ch=fill() fill(ch) p=precision() precision(p) w=width() width(w) setf(flags) unsetf(flags) setf(flags) 10 5

istream >> get(ch) ch getstr(str) str get(str,max) str MAX get(str,max,delim) str MAX DELIM DELIM getline(str,max,delim ) str MAX DELIM DELIM peek(ch) count=gcount() get getline read byte read(str,max) MAX byte str seekg() seekg(pos,seek_dir) pos=tellg(pos) 11 ostream << put(ch) ch flush() write(str,size) str SIZE byte seekp(position) seekp(position,seek_dir) pos=tellp() 12 6

goodbit ( ) 0x00 eofbit 0x01 failbit 0x02 badbit 0x04 hardfail 0x08 13 int eof() int fail() int bad() int good() clear(int) EOF failbit badbit hardfail badbit hardfail 14 7

#include <iostream.h> void main(){ int i; cout <<"i="; cin >> i; cout <<"Good ="<<cin.good()<<"\n"; cout <<"Eof ="<<cin.eof()<<"\n"; cout <<"Fail ="<<cin.fail()<<"\n"; cout <<"Bad ="<<cin.bad()<<endl; i=5 Good=1 Eof =0 Fail =0 Bad =0 i=a Good=0 Eof =0 Fail =2 Bad =0 15 / ifstream: ofstream: fstream : Step 1: Step 2: Step 3: 16 8

#include <fstream.h> 17 : ifstream ofstream ostream fout( data,ios::out); : open ifstream fin; fin.open( data,ios::in) 18 9

open in out ate (AT End) app (Append) trunc (Truncate) nocreate noreplace binary 19 istream seekg(long, ) ostream seekp(long, ) ios::beg ios::cur ios::end long tellg() long tellp() 20 10

ifstream ( ) #include <iostream.h> #include <fstream.h> void main(){ char fname[20]; cout<<"file name="; cin >>fname; // ifstream fin(fname,ios::in ios::binary); // fin.seekg(0l,ios::end); // cout<<"file length="<<fin.tellg()<<endl; 21 : 0x1a ^Z : DOS 0x0D 0x0A ^M(CR) ^J(LF) C/C++ 0x0A ^J(LF) cin >> getline get cout << put 22 11

#include <iostream.h> #include <fstream.h> const int linelen=200; void main(){ char fname[20]; ifstream fin; ofstream fout; char str[linelen]; cerr<< "From file="; cin >> fname; fin.open( fname,ios::in); cerr<< "To file="; cin >> fname; fout.open( fname,ios::out); while (!fin.eof()){ fin.getline(str,linelen,'\n'); fout <<str<<endl; 23 : ifstream read ofstream write 24 12

cout << cout << obj operator << (cout,obj) ostream& operator<<(ostream &os, & ) 25 void main(){ #include <iostream.h> complex a(2,-1); class complex{ cout <<a; float real; float imag; public: complex(float r=0, float i=0){ 2+ -1i real=r; imag=i; friend ostream& operator <<(ostream&, complex&); ; ostream& operator<<(ostream& os, complex& c){ os << c.real <<"+ "; os << c.imag<<"i"; return os; 26 13

cin >> cin>> obj operator >> (cin,obj) istream& operator>>(istream &is, & ) 27 #include <iostream.h> is >> m.phone; class man{ return is; char name[40]; char phone[10]; ostream& operator<<(ostream& os, public: man &m){ friend istream& os << "Name : "<<m.name<<endl; operator>>(istream&, man&); os << "Phone: "<<m.phone<<endl; friend ostream& returnos; operator<<(ostream&, man&); ; void main(){ istream& operator>>(istream& is, man Tom; man& m){ cin >> Tom; cout <<"Name:"; cout << Tom; is >> m.name; cout << "Phone:"; 28 14