如何在C ++中正确访问org-mode表数据?
#+tblname: prob-calc
| a | 353.02 |
| b | 398.00 |
| c | 241.0 |
| d | 1 |
#+begin_src C++ :var tbl=prob-calc :includes <stdio.h> :results output
// in other languages, say python, you can just evaluate tbl to
// see the values (and of course access them in the usual python
// way. Same for R, Common Lisp. Is it possible with C++? My
// suspicion is that it can't be done in C++.
// What goes here to do it?
#+end_src
提前致谢
答案 0 :(得分:1)
这似乎有效:
#+tblname: prob-calc
| a | 353.02 |
| b | 398.00 |
| c | 241.0 |
| d | 1 |
#+begin_src C++ :var tbl=prob-calc :includes <iostream> <cstdlib> :results output
int row, col;
for (row=0; row < tbl_rows; row++) {
for (col=0; col < tbl_cols; col++) {
std::cout << tbl[row][col] << " ";
}
std::cout << "\n";
}
#+end_src
#+RESULTS:
: a 353.02
: b 398.0
: c 241.0
: d 1
在Linux上,源文件是用/tmp/babel-<mumble>/C-src-<mumble>.cpp
编写的,该文件中的表声明如下所示:
const char* tbl[4][2] = {
{"a","353.02"},
{"b","398.0"},
{"c","241.0"},
{"d","1"}
};
const int tbl_rows = 4;
const int tbl_cols = 2;