从函数获取两个数组并将它们存储在C++中不同数据类型的数组中

Bla*_*ite 2 c++ arrays function data-structures

我有一个包含多个数组的函数,我想以这种方式在我的主函数中使用这两个数组

void fun ()    //which data type should I place here int OR char ?
{
    int array[4]={1,2,3,4}
    char array2[3]={'a','b','c'}

    return array,array2;
}
Run Code Online (Sandbox Code Playgroud)
int main(){

    int array1[4];
    char array2[3];


    array1=fun();  is it possible to get these array here ?
    array2=fun();
}
Run Code Online (Sandbox Code Playgroud)

Ted*_*gmo 6

如果你真的想返回数组,你可以将它们放在 a std::pairof std::arrays 中:

#include <array>
#include <utility>

auto fun() {
    std::pair<std::array<int, 4>, std::array<char, 3>> rv{
        {1, 2, 3, 4},
        { 'a', 'b', 'c' }
    };

    return rv;
}

int main() {
    auto[ints, chars] = fun();
} 
Run Code Online (Sandbox Code Playgroud)