In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "C++ format control character scanf and printf input and output methods", in daily operation, I believe many people in C++ format control character scanf and printf input and output methods have doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "C++ format control character scanf and printf input and output methods" doubts helpful! Next, please follow the small series to learn together!
Use Scanf input and Printf output
These are two functions in C.
1. Use of Scanf
Format:
scanf("format control", variable address);scanf("%d",&n);
scanf formatter for common data type variables
int%dlong %lldfloat%fchar%cdouble%lf String (char array)%s
Like 13:45:20, you can type that.
scanf("%d:%d:%d",&h,&m,&s);
Except for %c, scanf inputs other formatting characters with blank characters (spaces, tabs) as the end judgment flag, character arrays with %s read with spaces and newlines as the end of reading flags, %c can read spaces and newlines.
printf("format control", variable name);
Format control character only double becomes %f
If you want to print % , just add a % \to the front.
Common output format 1. %md
Int-type variables with less than m bits can be right-aligned output with m bits, and the high bits are filled with spaces. If they exceed m bits, they remain unchanged.
#includeusing namespace std;int main(){ int a=123,b=123456; printf("%5d\n",a); printf("%5d\n",b); return 0;}
123
123456
2、%0md
Different from %md, when the variable is less than m bits, complement 0.
#includeusing namespace std;int main(){ int a=123,b=123456; printf("%5d\n",a); printf("%5d\n",b); printf("d\n",a); return 0;}
123
123456
00123
3、%.mf
Floating-point numbers can be output with m decimal places
#includeusing namespace std;int main(){ double d=3.14159; printf("%.0f\n",d); printf("%.1f\n",d); printf("%.2f",d); return 0;}
3
3.1
3.14
Third, use getchar input putchar output a single character
Can recognize newline characters
char c1,c2;c1=getchar();c2=getchar();putchar(c1);putchar(c2); At this point, the study of "C++ format control character scanf and printf input and output methods" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.