I found here in the org manual how to output from an org-babel source-code block to an org-mode table, namely through something like
#+header :results output table
I have had some trouble getting org-mode to interpret separator rows in output correctly, however, Here is an example
#+name: stack_overflow_mve
#+header: :exports results
#+header: :results output table
#+begin_src C++ :noweb yes :results output :flags -std=c++14 :includes '(<algorithm> <functional> <iostream> <cmath> <string.h> <stdio.h> <stdlib.h> <iomanip>)"
double means [] {0.23, 0.77, 2.05, 3.8, 6.35};
double stddevs [] {0, 0.763675, 2.28184, 3.965, 6.65608};
size_t total_count = sizeof(means) / sizeof(means[0]);
std::cout << "count " << "mean " << "std_dev" << std::endl;
std::cout << "-----|" << "----|" << "------|" << std::endl;
for (size_t count = 0; count < total_count; ++count) {
std::cout << count + 1 << " ";
std::cout << means[count] << " ";
std::cout << stddevs[count] << " " << std::endl;
}
#+end_src
The code block above produces the following almost-table. As you can see, the separators on the second line are not correct. That incorrectness hinders my ability to feed the table to some later code blocks without manual intervention.
#+RESULTS: stack_overflow_mve
| count | mean | std_dev |
| ----- | ---- | ------ |
| 1 | 0.23 | 0 |
| 2 | 0.77 | 0.763675 |
| 3 | 2.05 | 2.28184 |
| 4 | 3.8 | 3.965 |
| 5 | 6.35 | 6.65608 |
If I put the cursor inside the table on the second line, replace the first space with a -
and press TAB
, org-mode corrects it to the following:
| count | mean | std_dev |
|-------+------+----------|
| 1 | 0.23 | 0 |
| 2 | 0.77 | 0.763675 |
| 3 | 2.05 | 2.28184 |
| 4 | 3.8 | 3.965 |
| 5 | 6.35 | 6.65608 |
Of course, I want to do that with my code so that my document is fully automated. Here are a bunch of attempts, each of which produces some hilariously differently wrong results:
//std::cout << "|-----+-----+-----|" << std::endl;
//std::cout << "|-----|-----|-----|" << std::endl;
//std::cout << "-----\t" << "---- \t" << "------" << std::endl;
//std::cout << "----- " << "---- " << "------ " << std::endl;
//std::cout << "------" << "-----" << "-------" << std::endl;
I was unable to find specific info in the org-manual about how to format separator lines correctly from org-babel code.
:colnames
header argument? Some of theob
libraries support a list as an argument, i.e.:colnames '("count" "mean" "std_dev")
in your case.