Exercises, examples and other material relating to training module C235. This topic is presented on public courses Learning to program in C++
, C++ for C Programmers
, C and C++ Programming
The C++ streams library and output formatters provide you
with an Object Oriented approach to user and file interaction.
You can define an object's behaviour - which is much more
efficient than having to format your output every single time.
|Articles and tips on this subject||updated|
|3807||Reading (and writing) files in C++|
"But how do I read data from a file ....?". Question on a C++ course on which we had concentrates, thus far, on object orientation.
1. Include the fstream header file
2. Create an object of type ifstream using the constructor, and passing in the file name
3. Read lines from the ifstream ...
|3810||Reading files, and using factories to create vectors of objects from the data in C++|
On our C++ courses, we concentrate on objects and object design. But we also take a wider look at topics such as references and templates that go to making the complete language, with sections covering changes to things like file handling from the underlying C language.
I've just added a new example ...
|3390||Printing objects in C++|
Overloading operators with methods is a great way of providing a shorthand using the operator syntax for common things you want to do with objects. In other words - it's much easier to write:
c = a + b
c = a.addition(b)
ans it's also much easier for the maintainance ...
|3252||C++ - unknown array size, unknown object type. Help!|
There are time when you're writing a program where you say "I don't know".
• I don't know how many records / object I'm going to read from a data file into an array - so I can't set the size of my array
• I don't know what sort of object I'll be creating from a line I've read from a data ...
|3124||C++ - putting the language elements together into a program|
On the final day of the C++ course yesterday, I demonstrated a number of advanced features and pulled together various strands that we had been learning through the week. At one level, each feature of the language can be explained and taught, but there's a further level that's need to show how they ...
|1675||Comparing Objects in C++|
Comparing two objects
You can run a method on an object in C++ (or in any other OO language) to find an attribute of that object - let's say how costly it is (example, how costly it is to jave your group see a film). But you can't really run a method on TWO or more objects, which is what you would ...
|1478||Some new C programming examples - files, structs, unions etc|
A series of new "C" examples have been added to the web site - a course for a small group allowed me to go somewhat away from the more normal run yesterday and write some new illustrations in front of them.
Call by value v call by pointer comparison: link
Using extern to share a variable between two ...
Examples from our training material
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from http://www.training-notes.co.uk
Topics covered in this module
The streams libraries.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.