c++3-07-08 - inp>>a>>b>>c; int d;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
March 7, 2008 C++ File I/O *Input/Output from/to disk files *Why? --large input --data from another program -binary i/o -Repetitive input -Archival Storage of Output C++ interface to files employs variables of file Type: Istream-- cin #include<iostream> Ostream- cout, cerr #include <fstream> Ifstream using namespace std; ofstream Use file streams: similar to cin/cout: << output >> input difference: can have an arbitrary number of ifstream and ofstream variables file streams must be explicitly opened. Opening files: #include <fstream> using namespace std; Int main() { ifstream inp; inp.open (“input.txt”); int a, b, c;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: inp>>a>>b>>c; int d; inp>>d; //gets 10 or ifstream inp(input.txt:); int main() { ifstream inp; inp.open(input.txt); ../data/input.txt if (inp.fail()) cerr<<Could not open file.\n; else { int a,b,c; inp>>a>>b>>c; //copy file #include <fstream> using namespace std; int main() { ifstream inp*source.txt); ofstream out; out.open(copy.txt); create if it doesnt exist or overwrite it if it does int a, b, c; inp>>a>>b>>c; out<<a<< <<b << <<c<< \n; formatting ofstream out; out.open(Log.txt, ios::app);...
View Full Document

This note was uploaded on 04/17/2008 for the course EECS 168 taught by Professor Miller during the Spring '08 term at Kansas.

Page1 / 2

c++3-07-08 - inp>>a>>b>>c; int d;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online