码迷,mamicode.com
首页 > 编程语言 > 详细

C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较

时间:2019-10-22 11:03:30      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:tail   输出   printf   int   处理   用法   pst   name   iostream   

#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
    char *pstr = "china";
    char *qstr = "america";
    char *q = "adf";
    char * s;
    s = "hello";

    printf("pstr = %p\n", pstr);  /*输出为字符串起始地址值*/
    /*由于C++标准库中I / O类对 << 操作符重载,因此在遇到字符型指针时会将其当作字符串名来处理,输出指针所指的字符串。
    https://blog.csdn.net/u013467442/article/details/43666955 */
    cout << "pstr = " << pstr << endl;  /*输出为字符串*/
    printf("pstr = %s\n", pstr);  /*输出为字符串*/
    
    cout << "qstr = " << qstr << endl;
    cout << "q = " << q << endl;
    cout << "s = " << s << endl;
    printf("s = %p\n", s);
    return 0;
}

技术图片

C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较

标签:tail   输出   printf   int   处理   用法   pst   name   iostream   

原文地址:https://www.cnblogs.com/HongjianChen/p/11489243.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!