C And C Based IO
Dec 27, 2015
C++
• C++ introduced new features to C– Objects• Collection of data with associated behaviors
– Templates– References– …
Current Relation
• C and C++ separate languages, separate governing bodies
• C++ often adopts changes in C, not always
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
Printf Formatting
• Format Codes:– %0numbercode • Pad with 0s
– %+numbercode • Print + for positive
– % numbercode : • Space for +
Printf Formatting
• For floating point – %.2f • any number of chars, 2 decimal places
– Default behavior : %.6
assume e = 2.718281828:
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
Scanf
• Can scan from formatted strings:
• Space in format string = unlimited whitespace
Skip unlimited white space before reading