Reputation: 180
How do I print signed value of my variable? For example:
int main()
{
int variable_name = 2;
cout<<variable_name<<endl;
}
I want this code to print +2, not just 2. And I don't want to use such construction:
cout<<"+"<<variable_name<<endl;
Upvotes: 1
Views: 64
Reputation: 2234
std::showpos
is what you're looking for:
http://www.cplusplus.com/reference/ios/showpos/
Upvotes: 3