C++
  Home arrow C++ arrow Custom Stream Manipulation in C++
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Custom Stream Manipulation in C++
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-05-05

    Table of Contents:
  • Custom Stream Manipulation in C++
  • Manipulators with No Argument
  • Solution for Multiple Arguments
  • Templates on the Fly

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Custom Stream Manipulation in C++


    (Page 1 of 4 )

    The creators of the STL library have surely gone beyond the expectations of many programmers. However, as perfect and complete as their library may seem at first, you will slowly discover that even they could not cover everything. That's when it is time for you to learn how to create a custom class/function that suits your specific needs.

    Before you venture any further, let me point out that this article is part of a larger series, each part of which will appear here on the Developer Shed Network. I invite you to read the earlier parts first to perfect your understanding of streams. The part directly connected to this one is titled General Stream Manipulation in C++.

    If you are only interested in how to create a custom manipulator, keep reading; otherwise, you'll want to read the earlier part. It covers what a manipulator is and how it works in general, so it serves as an excellent introduction for this article. 

    You may ask why it is that the manipulators that do not require arguments are in the iostream header, and the others are inside the iomanip header. This is due the fact that it is a little more complicated to pass a stream as an argument via the << operator inside a function. To achieve this, you need to declare a new class and functions that will operate behind the scene.

    That can consume quite a bit of space if you need to do it for a large list of manipulators. However, we should not rush so far ahead. Let me just state that you do this in separate ways for a small number of parameters and for a large number of parameters.

    You might require a custom manipulator for one of two reasons. First, you may want to group several already-written ones inside a new manipulator. In this way, each time you call the custom manipulator, all of the ones within it will be applied, allowing you to achieve the same result with less code, which may lead to a more readable view of the code snippet. Secondly, you may want to do something that is not implemented in the library.

    More C++ Articles
    More By Gabor Bernat


     

    C++ ARTICLES

    - More Tricks to Gain Speed in Programming Con...
    - Easy and Efficient Programming for Contests
    - Preparing For Programming Contests
    - Programming Contests: Why Bother?
    - Polymorphism in C++
    - Overview of Virtual Functions
    - Inheritance in C++
    - Extending the Basic Streams in C++
    - Using Stringstreams in C++
    - Custom Stream Manipulation in C++
    - General Stream Manipulation in C++
    - Serialize Your Class into Streams in C++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT