A Complete Guide to Programming in C++ part 43

A Complete Guide to Programming in C++ part 43. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | SOLUTIONS 399 default Invalid call to the program. cerr usage endl return 2 or exit 2 if strlen dest 0 Only source file yes output to cout. ifstream infile source if linfile openerror source ok copy infile cout The file is closed by the ifstream destructor. else Copy source to destination file in binary mode. ifstream infile source ios in ios binary if linfile openerror source else ofstream outfile dest ios out ios binary if loutfile openerror dest ok copy infile outfile if ok cerr File source to file dest copiedl endl if lok cerr Error while copying endl return 3 return 0 bool copy istream is ostream os To copy is to os. const int BufSize 1024 char buf BufSize do buf BufSize if 0 buf while if return false else return true 400 CHAPTER 18 FUNDAMENTALS OF FILE INPUT AND OUTPUT Exercise 2 ------------------------------------------------------- Header file for and . ------------------------------------------------------- include iostream include iomanip include fstream using namespace std Structure of a record struct Pizza char name 32 float price define MAXCNT 20 Maximum number of pizzas define FILENAME inline void header cout P I Z Z A P R O N T O n n endl ------------------------------------------------------- Demonstrating blockwise writing of records. ------------------------------------------------------- include Pizza pizzaMenu MAXCNT Pepperoni White Pizza Ham Pizza Calzone int cnt 4 char pizzaFile 256 FILENAME int main Write records. int i header cout nOur standard offer n endl cout fixed setprecision 2 for i 0 i cnt i cout setw 20 pizzaMenu i .name setw 10 pizzaMenu i .price endl cout n-------------------------------------------- n endl SOLUTIONS 401 Input more pizzas via keyboard while cnt MAXCNT cout What pizza should be added to the menu n n Name pizzaMenu cnt .name 32 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.