我正在尝试将二维和单维字符串数组传递给函数,但它不起作用。
我的数组是:
string 2Darray[100][100];
String 1Darray[100];
现在的功能:
void check(string temp2D[100][100], string temp1D[100]);
当我调用它时:
check(2Darray,1Darray);
我已经尝试过其他方式,但它们都不起作用。提前感谢您的任何答案!
我正在尝试将二维和单维字符串数组传递给函数,但它不起作用。
我的数组是:
string 2Darray[100][100];
String 1Darray[100];
现在的功能:
void check(string temp2D[100][100], string temp1D[100]);
当我调用它时:
check(2Darray,1Darray);
我已经尝试过其他方式,但它们都不起作用。提前感谢您的任何答案!
您可以更改为接受引用:
void check(string (&temp2D)[100][100], string (&temp1D)[100]);
或指针:
void check(std::string temp2D[][100], std::string temp1D[]){}
这与以下相同,只是语法不同:
void check(std::string (*temp2D)[100], std::string* temp1D){}
此外,您不能以数字、2Darray
等开头变量名是编译器错误。
这是一个完整的工作示例:
#include <string>
void check(std::string (&temp2D)[100][100], std::string (&temp1D)[100]){}
int main()
{
std::string twoDarray[100][100];
std::string oneDarray[100];
check(twoDarray,oneDarray);
}