Develop a C++ program to find the given number is positive or negative using user-defined manipulators.
#include <iostream>
#include <iomanip>
using namespace std;
// manipulator defines a positive or negative value
// to show a positive sign on positive numbers.
ostream&positive_negative(ostream&out) {
cout << showpos;
return out;
}
int main(){
int N;
cout<<"Enter N: ";
cin >> N;
cout << positive_negative << N << endl<<endl;
cout<<"Enter N: ";
cin >> N;
cout << positive_negative << N << endl;
return 0;
}
Comments
Leave a comment