Home arrow C++ arrow Page 4 - Iostream Library and Basic I/O in C++
C++

Iostream Library and Basic I/O in C++


The foundation of every relationship is communication. The quality of the communication is the first factor that determines the way the relationship evolves. This statement also holds true in the world of C++, and to raise the quality of communication, a library called iostream has been implemented.

Author Info:
By: Gabor Bernat
Rating: 5 stars5 stars5 stars5 stars5 stars / 6
March 24, 2009
TABLE OF CONTENTS:
  1. · Iostream Library and Basic I/O in C++
  2. · The Iostream Library
  3. · Basic I/O in C
  4. · Conclusion

print this article
SEARCH DEVARTICLES

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.

blog comments powered by Disqus
C++ ARTICLES

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- 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++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials