我有一个包含多个数组的函数,我想以这种方式在我的主函数中使用这两个数组
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::array
s的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/