This C++ Program which reads in the values of different primitive datatypes. The program uses input streams to take in the values of the primitive datatypes.
Here is source code of the C++ program which reads in the values of different primitive datatypes. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Read Primitive Datatypes
*/
#include <iostream>
using namespace std;
int main()
{
int integer;
char character;
float float_value;
double double_value;
bool boolean;
cout << "Non-zero value stands for true and "
<< "anything else for false " << endl;
cout << "Enter the boolean value : ";
cin >> boolean;
cout << "Enter an integer value : ";
cin >> integer;
cout << "Enter the character : ";
cin >> character;
cout << "Enter the float value : ";
cin >> float_value;
cout << "Enter the double value : ";
cin >> double_value;
cout << endl;
cout << "Integer : " << integer << endl
<< "Character : " << character << endl
<< "Float : " << float_value << endl
<< "Double : " << double_value << endl
<< "Boolean : " << boolean;
}
$ g++ main.cpp $ ./a.out Non-zero value stands for true and anything else for false Enter the boolean value : 1 Enter an integer value : 123 Enter the character : a Enter the float value : 12.3 Enter the double value : 12.333333 Integer : 123 Character : a Float : 12.3 Double : 12.3333 Boolean : 1
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy C++ Books
- Practice Programming MCQs
- Practice Computer Science MCQs
- Apply for Information Technology Internship
- Apply for Computer Science Internship