C/C++ 输出整数带正负号
生活随笔
收集整理的這篇文章主要介紹了
C/C++ 输出整数带正负号
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
格式控制符設為 %+d 即可
#include <bits/stdc++.h> using namespace std; int main() {printf("%+d\n", -1);printf("%+d\n", 0);printf("%+d\n", 1);cout << showpos << -1 << endl; // noshowpos 可以取消顯示正號cout << showpos << 0 << endl;cout << showpos << 1 << endl;return 0; }輸出:
-1 +0 +1 -1 +0 +1總結
以上是生活随笔為你收集整理的C/C++ 输出整数带正负号的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 二分查找自用模板
- 下一篇: 【模拟】P1067 多项式输出