c++ string 另类写法

#include <string>
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    string strOutput = "Hello World";

    cout << "[cout] strOutput is: " << strOutput << endl;

    // string 转换为 char*
    const char* pszOutput = strOutput.c_str();

    printf("[printf] strOutput is: %s\n", pszOutput);


    string sstr1(strOutput);

    cout << "sstr1= " << sstr1<< endl;


    return 0;
}
 
[cout] strOutput is: Hello World
[printf] strOutput is: Hello World
sstr1= Hello World
posted @ 2022-08-19 22:46  luoganttcc  阅读(5)  评论(0)    收藏  举报