C++入门经典-例2.2-使用格式输出函数printf

1:使用printf函数对不同类型变量进行输出,%符号,代表输出类型,\n代表换行,代码如下:

// 2.2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

 
 int main()
{
    int iInt=10;                                    /*定义整型变量*/
    char cChar='A';                                /*定义字符型变量*/
    float fFloat=12.34f;                            /*定义单精度浮点型*/

    printf("the int is: %d\n",iInt);                    /*使用printf函数输出整型*/
    printf("the char is: %c\n",cChar);                /*输出字符型*/
    printf("the float is: %f\n",fFloat);                    /*输出浮点型*/
    printf("the stirng is: %s\n","I LOVE YOU");            /*输出字符串*/
    return 0;
}
View Code

运行结果如下:

 

posted @ 2017-09-08 15:17  一串字符串  阅读(1094)  评论(0编辑  收藏  举报