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 212 views
1 answer 228 views
1 answer 154 views
154 views asked Apr 10, 2018 by avibootz
1 answer 226 views
1 answer 171 views
171 views asked Apr 9, 2018 by avibootz
...