[英]Passing a 2D array of strings to a function in c++
我正在尝试将字符串的二维和单个维度数组传递给函数,但是它不起作用。
我的数组是:
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.