Download presentation
Presentation is loading. Please wait.
Published byJasmin Ross Modified over 8 years ago
1
C And C Based IO
2
C C = portable assembly language Developed 1972 w/Unix – Systems focus
3
C++ C++ introduced new features to C – Objects Collection of data with associated behaviors – Templates – References – …
4
Current Relation C and C++ separate languages, separate governing bodies C++ often adopts changes in C, not always
5
Why Two Languages Tools C++ provides give us – Ways to program in different styles – Ways to build tighter abstractions – Ways to make things more/less efficient C gives us – Simplicity – De facto standard for linking code
6
C++ Bootstrapped on C C++ provides own versions of common c libraries
7
Libraries C++ and C libraries are subtly different
8
C IO No cin/cout objects – Use functions: C++ LibraryC Library
9
Printf Printf prints formatted strings: As many extra parameters as format codes
10
Printf Format Codes:
11
Examples Basic formatting
12
Printf Formatting Format Codes: – %numbercode : min width -number : left justify
13
Printf Formatting Format Codes: – %0numbercode Pad with 0s – %+numbercode Print + for positive – % numbercode : Space for +
14
Printf Formatting For floating point – %.2f any number of chars, 2 decimal places – Default behavior : %.6 assume e = 2.718281828:
15
Printf Formatting Examples
16
Scanf Scanf reads formatted strings into variables
17
Scanf Scanf reads information into variables:
18
Addresses Two meanings for & int& x – C++ only : variable is a reference to another int variable &x (x already exists) – C/C++ : address of x
19
Scanf Scanf reads information into variables: – Wants address of anything it is reading in
20
Scanf Type mismatch = weird errors:
21
Scanf Can scan from formatted strings: Space in format string = unlimited whitespace Skip unlimited white space before reading
22
Why Do I Care If you are writing C C functions may make life easier: C printf("%10.3f", &x); C++ cout << fixed << setprecision(3) << setw(10) << x;
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.