CS 150 - Brief C++ Facts Review

















CS 150 - Structure Chart Symbols





















CS 150 - C++ Executable Statements

The Three Types We Know About

















CS 150 - C++ Input Methods - from the keyboard



















CS 150 - C++ Input Methods



















Sample Input Operations





int number;
float cost;
char type;

// with this executable statement

cin >> cost >> number >> type;

With the following typed at the keyboard:

    34.56
            8
                  T

What Happens?



Suppose at the keyboard you type:

34.56    8    T

Now What Happens?

















CS 150 - C++ Input Methods - keyboard and external file





















Examples of input stream functions



    open           close
    get           getline
    eof           fail















C++ Steps in Using External Files



  1. Include fstream library
  2. Declaration of stream variable
  3. Open stream variable (associate with file)
  4. Operate on file -- extract values
  5. Close file (break the association)














C++ Input External File Example



//Include fstream

#include < fstream>
int main ()
    {
      char achar;
      int number;
// Declaration of stream variable

      ifstream myin;
// Open stream variable (associate with file)

      myin.open ("myinputfile");
// Operate on file -- extract values

      myin.get (achar); // ***OR*** myin >> achar;
      myin >> number;
// Close the disk file (break the association)

      myin.close ();
      return 0;
    }

















CS 150 C++ Output Methods

















CS 150 C++ Output Methods



















Output Using External Files

















C++ Steps in Using External Files



// Include fstream

#include < fstream>

// Declaration of stream variable

ofstream myout;

// Open stream variable (associate with file)

myout.open ("myoutputfile.dat");

// Operate on file -- perform output

myout.put (achar);
myout << achar;
myout << " " << number;

// Close file

myout.close ();















C++ Output Formatting



















C++ Output Formatting Manipulations

















Common C++ Formatting Flags



















Common C++ Formatting Manipulators