我正在尝试在c ++中打印一个二维数组,但是我遇到了问题。我遵循传统的方法在for循环中打印向量const mongoose = require('mongoose');
const variantSchema = new mongoose.Schema({
title: String,
available: Number,
_sku: String,
_skuSuffix: String,
});
variantSchema.virtual('skuSuffix')
.set(function setSkuSuffix(skuSuffix) {
if (!skuSuffix) return;
const parent = this.parent();
if (parent._skuPrefix) {
child._sku = `${parent._skuPrefix}-${child._skuSuffix}`;
}
})
.get(function getSkuSuffix() {
return this._skuSuffix;
});
variantSchema.virtual('sku').get(function getSku() {
return this._sku;
});
module.exports = variantSchema;
。所以我遵循的方式是这样。
const product = new Product(jsonObj);
但这就是这样打印
let variant;
if (jsonObj.variants) {
variant = jsonObj.variants;
delete jsonObj.variants;
}
const newProduct = new Product(jsonObj);
if (variant) {
if (newProduct.variants.length) {
// copy function detail not shown
copyFromObjToProduct(variant, newProduct.variants[0]);
} else {
newProduct.variants.push(variant);
}
}
预期输出
vectorName.size()
如何正确打印矢量?
答案 0 :(得分:3)
问题基本上是如何填充向量:
User.html
更高效,因为您仍然希望拥有相同的数据:
Dim sr As Series
For Each sr In ct.SeriesCollection
sr.Delete
Next
With ct.SeriesCollection.NewSeries
.Name = "A"
.Values = a
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "B"
.Values = b
.XValues = x
End With
With ct.SeriesCollection.NewSeries
.Name = "C"
.Values = c
.XValues = x
End With
答案 1 :(得分:0)
打印std::vector
中的std::vector
的两种简单方法:
#include <vector>
#include <iostream>
int main()
{
std::vector<std::vector<int>> foo{
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 }
};
// range-based for-loops:
for (auto const &row : foo) {
for (auto const &col : row) {
std::cout << col << ' ';
}
std::cout.put('\n');
}
std::cout.put('\n');
// ordinary for-loops:
for (std::size_t row{}; row < foo.size(); ++row) {
for (std::size_t col{}; col < foo[row].size(); ++col) {
std::cout << foo[row][col] << ' ';
}
std::cout.put('\n');
}
}