可以使用vector来存储这三个string,并将vector转换为string array。

示例代码:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string str1 = "hello";
    string str2 = "world";
    string str3 = "!";
    
    vector<string> strVec = {str1, str2, str3};
    
    string strArr[3];
    
    for(int i = 0; i < 3; i++) {
        strArr[i] = strVec[i];
    }
    
    // 输出string array
    for(int i = 0; i < 3; i++) {
        cout << strArr[i] << " ";
    }
    cout << endl;
    
    return 0;
}

输出结果:

hello world ! 
使用C++将三个string转换为 string array

原文地址: https://www.cveoy.top/t/topic/bjiJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录