[标准C/C++基础]用指针指向string类的对象

来源:互联网 发布:流程设计软件 编辑:程序博客网 时间:2024/06/05 16:55
  1. #include<iostream>  
  2. #include<string>  
  3. using namespace std;  
  4.   
  5. int main(void)  
  6. {  
  7.  string s = "hello";  
  8.  //定义一个char类型指针,把string s的首元素地址赋给pt,则pt指向字符串s.  
  9.  char *pt = &s[0];   
  10.  cout << pt << endl;  
  11.  return 0;  
0 0