zoukankan      html  css  js  c++  java
  • c++ string char* const char*

    #include <iostream>
    #include <string>
    #include <cstring>
    using namespace std;
    
    int main()
    {
        {
            string s = "tom and jerry";
            const char* c_s = s.c_str();
            cout << "---------------" << endl;
            cout << c_s << endl;
            cout << s << endl;
        }
    
        {
            const char* c_s = "tom and jerry";
            string s(c_s);
            cout << "---------------" << endl;
            cout << c_s << endl;
            cout << s << endl;
        }
    
        {
            string s = "tom and jerry";
            char* c;
            const int len = s.length();
            c = new char[len+1];
            strcpy(c, s.c_str()); //#include <cstring>
            cout << "---------------" << endl;
            cout << c << endl;
            cout << s << endl;
        }
    
    
        {
            char* c = "tom and jerry";
            string s(c);
            cout << "---------------" << endl;
            cout << c << endl;
            cout << s << endl;
        }
    
        {
            const char* c = "tom and jerry";
            char* pc = new char[100];
            strcpy(pc, c);
            cout << "---------------" << endl;
            cout << c << endl;
            cout << pc << endl;
        }
    
    
        return 0;
    }
  • 相关阅读:
    sqoop基本命令
    sqoop-介绍及安装
    HBase与Hive的集成操作
    Phoenix简介及操作
    HBase-Rest API操作
    HBase-Java Native API操作
    HBase-shell操作
    HBase-基本架构
    HBase-物理模型
    HBase-集群安装
  • 原文地址:https://www.cnblogs.com/i80386/p/4387128.html
Copyright © 2011-2022 走看看