gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:44:54 24 4
gpt4 key购买 nike

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

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;
}
int main(){

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


array1=fun(); is it possible to get these array here ?
array2=fun();
}

最佳答案

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

#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();
}

关于c++ - 从函数中获取两个数组并将它们存储在 C++ 中的不同数据类型数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74840938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com