在制作BP神经网络时,需要给vector添加一个空行,自己根据直觉进行了以下试探,发现并没有问题。
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<vector<int>> vv;
vv.push_back({});
vv.push_back({});
cout << vv.size() << endl;
vv[1].push_back(0);
cout << vv[0].size() << endl;
cout << vv[1].size() << endl;
system("pause");
return 0;
}
输出:
扩展到三维数组
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<vector<vector<int>>> vv;
vv.push_back({});
vv.push_back({});
cout << vv.size() << endl;
cout << vv[0].size() << endl;
vv[0].push_back({});
cout << vv[0].size() << endl;
system("pause");
return 0;
}
运行结果: