2次元配列も定義できるようだが、 こちらはカギ括弧 [ ] は使えず、 丸括弧 ( ) を使う必要があるみたい。
| 2次元配列はこんなふうに |
real[int,int] a(2,2); a(1,1)=1; a(1,2)=2; a(2,1)=3; a(2,2)=4; |
| 2次元配列の例 (丸い括弧を使う) |
real[int,int] a(3,2);
a(0,0)=1; a(0,1)=2;
a(1,0)=3; a(1,1)=4;
a(2,0)=5; a(2,1)=6;
cout << "a.n=" << a.n << ", a.m=" << a.m << endl; // 3と2になる。
for (int i=0; i < a.n; i++) {
for (int j=0; j < a.m; j++)
cout << setw(4) << a(i,j) << " ";
cout << endl;
}
cout << "output by \"cout<<a<<endl;\"" << endl;
cout << a << endl;
|
| 2次元配列の例 (丸い括弧を使う) |
$ FreeFem++ foo.edp
-- FreeFem++ v4.700001 (Jeu 5 nov 2020 11:02:28 CET - git v4.7-1)
Load: lg_fem lg_mesh lg_mesh3 eigenvalue
1 : real[int,int] a(3,2);
2 : a(0,0)=1; a(0,1)=2;
3 : a(1,0)=3; a(1,1)=4;
4 : a(2,0)=5; a(2,1)=6;
5 : cout << "a.n=" << a.n << ", a.m=" << a.m << endl; // 3と2になる。
6 : for (int i=0; i < a.n; i++) {
7 : for (int j=0; j < a.m; j++)
8 : cout << setw(4) << a(i,j) << " ";
9 : cout << endl;
10 : }
11 : cout << "output by \"cout<<a<<endl;\"" << endl;
12 : cout << a << endl;
13 : sizestack + 1024 =1168 ( 144 )
a.n=3, a.m=2
1 2
3 4
5 6
output by "cout<<a<<endl;"
3 2
1 2
3 4
5 6
times: compile 0.01818s, execution 0.000271s, mpirank:0
CodeAlloc : nb ptr 3611, size :458584 mpirank: 0
Ok: Normal End
$
|