You can add row-by-row like this:
Code:
#include <iostream>
#include <string>
#include <vector>
#include <array>
using namespace std;
class A {
vector<array<string, 3>> v;
public:
A() { }
void add_row(const string& a, const string& b, const string& c) {
v.push_back({a, b, c});
}
void print() const {
for (const auto& row: v)
cout << row[0] << ' '
<< row[1] << ' '
<< row[2] << '\n';
}
};
int main() {
A a;
a.add_row("a", "b", "c");
a.print();
}
You might want to structure your data, something like:
Code:
#include <iostream>
#include <string>
#include <vector>
#include <array>
using namespace std;
struct Value {
string name;
int16_t value;
};
class A {
vector<array<Value, 3>> v;
public:
A() { }
void add_row(const string& a, int16_t av,
const string& b, int16_t bv,
const string& c, int16_t cv) {
v.push_back({Value{a,av}, Value{b,bv}, Value{c,cv}});
}
void print() const {
for (const auto& r: v) {
for (const auto& e: r)
cout << e.name << ':' << e.value << " ";
cout << '\n';
}
}
};
int main() {
A a;
a.add_row("a", 1, "b", 2, "c", 3);
a.add_row("d", 4, "e", 5, "f", 6);
a.print();
}