二维数组这样传值怎么不对呢?请大家帮帮我吧。
- C/C++ code
#include<iostream> #include<fstream> #include<string>#include<iomanip>using namespace std; void input_WolfSheep(string s[][]);void ordered_WolfSheep_nls(string s[][]);int main() { string s[200][100]; input_WolfSheep(s); ordered_WolfSheep_nls(s); cout<<endl; system("PAUSE"); return 0; }void input_WolfSheep(string **s){ int i=0,j=0; string name; ifstream infile("WolfSheep.nls",ios::in); if (!infile) { cerr<<"open error!"<<endl; exit(1); } for (i=0;i<200;i++) { for(j=0;j<100;++j) { infile>>s[i][j]; if(s[i][j]==';') break; } } infile.close(); //cout<<endl; }void ordered_WolfSheep_nls(string **s){ int j=0; ofstream outfile("WS_nocomment.nls",ios::out); if(!outfile) { cerr<<"open error!"<<endl; exit(1); } for(int i=0;i<200;i++) { for(j=0;j<100;++j) { if(s[i][j]!=";") { outfile<<s[i][j]; } else { break; } } } outfile.close(); return ;}[解决办法]
二维数组传递要求把第二维的大小给确定了。所以你需要指定第二维的大小。
void input_WolfSheep(string s[][6]);
void ordered_WolfSheep_nls(string s[][6]);
[解决办法]
LZ应该搞清楚
string s[][6]
和
string s[][]
是不一样的。
[解决办法]
数组是数组, 指针是指针, 楼主和没学过C语言一样, 实话实说.