C++
  Home arrow C++ arrow Page 4 - Iostream Library and Basic I/O 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++

Iostream Library and Basic I/O in C++
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-03-24

    Table of Contents:
  • Iostream Library and Basic I/O in C++
  • The Iostream Library
  • Basic I/O in C
  • Conclusion

  • 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


    Iostream Library and Basic I/O in C++ - Conclusion


    (Page 4 of 4 )

    All of this looks good, but what if you want to read a whole line of data? As you can see, the stream extraction will delimit each input flow by thewhitespaces it will find. This obviously makes it impossible to read a whole line. However, there is another way to accomplish this, by using the "getline" function.

    The result will be put into a string, though you need to include thestringheader and declare it. The function is also declared in this header in the form of a template, making it possible to work for both narrow or wide characters.


    #include <string>

    ...

    string putInTo;

    getline( cin, putInTo, ' n');


    I have explicitly requested to use as delimiter the newline character, just to show you that as the delimiter, you may use any character, but by default, it has defined the newline one. There you go; you've just learned the basics of how to communicate with users in C/C++.

    All that is left is to start playing with the compiler, experimenting with different situations, and getting used to the method. Don't you find this more practical than the standard I/O used in C/C++?

    You can answer this question or ask for further clarification regarding this article in the blog found right under this statement, or you can join our friendly, ever-growing forum over atDevHardware, and let the community over there answer your questions. Until the next time we meet, live with passion!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek