C++
  Home arrow C++ arrow Serialize Your Class into Streams 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++

Serialize Your Class into Streams in C++
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2009-04-21

    Table of Contents:
  • Serialize Your Class into Streams in C++
  • Why Should You Make Your Class Compatible with Streams?
  • The Insertion
  • The Extraction

  • 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


    Serialize Your Class into Streams in C++


    (Page 1 of 4 )

    Writing code in C++ is not a trivial task, but quite manageable for anyone who gets into his or her head the desire to achieve success in the coding segment of life. To make the coding process more understandable, C++ offers the stream concept. This article will be all about how to make your class compatible with this technology.

    So you started learning to code in C++. You know how to create a class, learned the golden rule that a "deconstructor" will always exist, and have decided that it's time to learn about streams. What a great tool to use if you know what it is all about.

    I assume you know how to use streams for writing some data to a file and not only to the console. If this statement is false in your case, I advise you to read some of my other articles on  this topic, published here on the Developer Shed Network. Once you understand that, then handling the serialization of objects with just a few lines will become manageable.

    However, there is a problem. When you try to pass to the stream, your very own and custom class (with its own internal members) the compiler just puts out an error that this is an invalid move. The reason for this issue is that the streams are compatible by default only with the default types known by C++. If all this is true in your case, you are in a right place, as here I will show you how to resolve it.

    This process, known also as insertion and extraction in streams, is an easy and practical way to resolve serialization. In the world of C++, I/O tasks are completed through the iostream library, which is an object-oriented class library that makes use of multiple and virtual inheritance. This is provided inside the "iostream" library as a component of C++.

    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 5 Hosted by Hostway
    Stay green...Green IT