How to use showpos cout format flag to set the plus sign (+) for non-negative numbers in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

int main()
{
	cout.setf(std::ios::showpos);

	cout << 31 << ' ' << -31 << endl;

	return 0;
}

/*
run:

+31 -31

*/

 



answered Apr 9, 2018 by avibootz

Related questions

1 answer 205 views
1 answer 225 views
1 answer 148 views
148 views asked Apr 10, 2018 by avibootz
1 answer 224 views
1 answer 166 views
166 views asked Apr 9, 2018 by avibootz
...