回答編集履歴
2
コード追記
test
CHANGED
@@ -19,3 +19,93 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
`n`は`m`のタイプミスだと思いますが、`m`が定数でないと`std::vector<unshort[m]>`は作れません。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
`m`が定数なら
|
30
|
+
|
31
|
+
```C++
|
32
|
+
|
33
|
+
#include<vector>
|
34
|
+
|
35
|
+
#include<iostream>
|
36
|
+
|
37
|
+
#define ushort unsigned short
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
int main() {
|
42
|
+
|
43
|
+
int n = 3;
|
44
|
+
|
45
|
+
int x = 2;
|
46
|
+
|
47
|
+
const int m = 4;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
ushort** a;
|
52
|
+
|
53
|
+
a = new ushort * [n];//nはint
|
54
|
+
|
55
|
+
for (int i = 0; i < x; i++) {
|
56
|
+
|
57
|
+
a[i] = new ushort[m];
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// ダミーデータ格納
|
62
|
+
|
63
|
+
for (int j = 0; j < m; j++)
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
a[i][j] = i * m + j;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
// コピー
|
76
|
+
|
77
|
+
std::vector<ushort[m]> b(x);
|
78
|
+
|
79
|
+
for (int i = 0; i < x; i++) {
|
80
|
+
|
81
|
+
std::copy(a[i], a[i] + m, b[i]);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
// 確認
|
88
|
+
|
89
|
+
for (int i = 0; i < x; i++) {
|
90
|
+
|
91
|
+
std::cout << "b[" << i << "]:";
|
92
|
+
|
93
|
+
for (int j = 0; j < m; j++)
|
94
|
+
|
95
|
+
{
|
96
|
+
|
97
|
+
std::cout << b[i][j] << " ";
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
std::cout << std::endl;
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
return 0;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
```
|
1
要素がunshort[n]なvectorについて追記
test
CHANGED
@@ -5,3 +5,17 @@
|
|
5
5
|
std::vector<std::vector<ushort>> a(n, std::vector<ushort>(m));
|
6
6
|
|
7
7
|
```
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
> ushort** を一つの要素がunshort[n]なvectorに変換
|
16
|
+
|
17
|
+
nはint
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
`n`は`m`のタイプミスだと思いますが、`m`が定数でないと`std::vector<unshort[m]>`は作れません。
|