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

#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;
}

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

时间: 2024-08-27 12:05:01

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

C++中cout输出字符型指针地址值的方法

#include<iostream> #include<string> using namespace std; int main(){ char c[3]={'a','b','c'}; char *p=c; cout<<*p<<' '<<(void*)p<<endl; cout<<*(p+1)<<' '<<static_cast<void*>(p+1)<<endl; cou

从客户端中检测到有潜在危险的 request.form值[解决方法]

当页面编辑或运行提交时,出现"从客户端中检测到有潜在危险的request.form值"问题,该怎么办呢?如下图所示: 从客户端中检测到有潜在危险的 request 下面博主汇总出现这种错误的几种解决方法: 问题原因:由于在asp.net中,Request提交时出现有html代码或javascript等字符串时,程序系统会认为其具有潜在危险的值.环境配置会报出"从客户端 中检测到有潜在危险的Request.Form值"这样的Error. 1.当前提交页面,添加代码 打

C 语言中的printf()多参数输出问题

问题: x=1; y=2; printf("%d",x+y,x++,y++); 输出结果为什么是5? 首先解释一点,x+y,x++,y++是逗号表达式,逗号表达式的结果是最后一个表达式的结果. 但是在这里printf()函数是从左往右读取,然后将先读取放到栈底,最后读取的放在栈顶,处理时候是从栈顶开始的,所以我们看见的结果是,从右边开始处理的. 读取入栈:                                                           处理计算:  

python中两个整数相除得到浮点数的值的方法

/********************************************************************* * Author  : Samson * Date    : 09/19/2014 * Test platform: *              Linux ubuntu 3.2.0-58-generic-pae *              GNU bash, version 4.2.39 * *****************************

cout输出字符串指针

先给出通过字符型指针输出字符串的示例代码,如下: #include <iostream>using std::cout;using std::endl; int main(){ const char *pszStr = "this is a string"; // 输出字符串cout << "字符串:" << pszStr << endl; // 显然不会输出地址值cout << "字符串起始地址

cout 输出字符串(指针)常见问题及put,write函数

C++ ostream类为下面的指针类型定义了插入运算符函数: const signed char *; const unsigned char *; const char *; void *; C++用指向字符串存储位置的指针来表示字符串,指针的形式可以是char数组名,显式的char指针或用引号括起来的字符串. 下面是一个简单输出字符串的例子: #include <iostream> using namespace std; int main() { char name[] = "

fprintf输出到文件中,sprintf输出到字符串中. 如: fprintf(fp,&quot;%s&quot;,name); fp为文件指针 sprintf(buff,&quot;%s&quot;,name); buff为字符数组

fprintf输出到文件中,sprintf输出到字符串中. 如: fprintf(fp,"%s",name); fp为文件指针 sprintf(buff,"%s",name); buff为字符数组 fprintf输出到文件中,sprintf输出到字符串中. 如: fprintf(fp,"%s",name); fp为文件指针 sprintf(buff,"%s",name); buff为字符数组

D Java中字符串转换成整型

字符串转换为整型 // //1.获取请求参数id String id = req.getParameter("id"); // //2.删除数据 bookService.deleteBookById(Integer.valueOf(id)); //======================================= //1.获取请求参数id Integer id = WebUtils.parseInt(req.getParameter("id"),0);

C++中关于string类型究竟能不能用cout输出的问题

先让我讲下故事哈 一次在MFC中用cout输出一个string类型字符串,编译时出现这样一个错误: error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or