p-ranav / tabulate

Table Maker for Modern C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to print std::vector<std::string> into a row?

ManNam1 opened this issue · comments

I need to convert vectors of string into table rows, but failing to do that. Could you please help?

After some time I have come up with a solution (I suppose not the best):
Table table;
std::vector<variant<std::string, const char *, string_view, Table>> header;
header.push_back("corner cell");
for (auto element : some_vector_of_strings)
{
header.push_back(element );
}
table.add_row(Row_t{header});

commented

Hello.

For a vector of strings, e.g.,

std::vector<std::string> stringVec{"A", "B", "C"};

You should be able to do this in one line:

Row_t header(stringVec.begin(), stringVec.end());

thank you very much, it works for me!