C++ Program to Demonstrate noskipws Manipulator

This C++ program demonstrates the noskipws manipulator. The manipulator prevents skipping the whitespaces when either characters are entered into operands via input stream or characters are output into output streams.

Here is the source code of the C++ program which demonstrates the noskipws manipulator. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to demonstrate noskipws manipulator
  3.  */
  4. #include <iostream>
  5. #include <sstream>
  6. #include <string>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     char first, middle, last;
  12.  
  13.     istringstream("G B S") >> first >> middle >> last;
  14.     cout << "Default behavior: First Name = " << first << ", Middle Name = " << middle << ", Last Name = " << last << '\n';
  15.     istringstream("G B S") >> noskipws >> first >> middle >> last;
  16.     cout << "noskipws behavior: First Name = " << first << ", Middle Name = " << middle << ", Last Name = " << last << '\n';
  17. }

$ gcc test.cpp
$ a.out
Default behavior: First Name = G, Middle Name = B, Last Name = S
noskipws behavior: First Name = G, Middle Name =  , Last Name = B

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.