码迷,mamicode.com
首页 > 其他好文 > 详细

字符串取地址

时间:2016-09-29 01:34:10      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include<string>
#include <cstring>
#include<vector>
#include<sstream>
#include<algorithm>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
char *p="fdg";
cout<<*(p+1)<<endl;;//p所指的位置是不变的与p++不同
cout<<*p<<endl;
cout<<p<<endl;
cout<<&p<<endl;//指针所在的地址
cout<<static_cast<const void *>(p)<<endl;//必须要转化成无类型指针,输出的是字符串首地址
string str="gjjlhklj";
cout<<str<<endl;
cout<<&str<<endl;
cout<<&str[0]<<endl;

cout<<static_cast<const void *>(&str[0])<<endl;
}
cout<<&str[0]<<endl;输出的事整个字符串
技术分享

 

 

字符串取地址

标签:

原文地址:http://www.cnblogs.com/8335IT/p/5918299.html

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