我试图将一个二维和单维字符串数组传递给一个函数,但它不起作用。
我的数组是:
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);
}
关于c++ - 将二维字符串数组传递给 C++ 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15352703/