- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请考虑函数f:
open Format
let rec f i = match i with
| x when x <= 0 -> ()
| i ->
pp_open_hovbox std_formatter 2;
printf "This is line %d@." i;
f (i-1);
printf "This is line %d@." i;
close_box ();
()
它递归地打开 hovboxes 并打印一些东西,然后是换行符提示 (@.)。当我调用 f 3
时,我得到以下输出:
This is line 3
This is line 2
This is line 1
This is line 1
This is line 2
This is line 3
但我预计:
This is line 3
This is line 2
This is line 1
This is line 1
This is line 2
This is line 3
您能解释一下为什么我获得第一个输出以及我需要更改什么才能获得第二个输出吗?
最佳答案
@.
不是换行提示,它等同于 print_newline
这叫print_flush
关闭所有打开的框并在其后跟一个新行。
如果你想用 Format
逐行打印,你应该用 open_vbox
打开一个垂直框并使用 print_cut
("@,"
) 每当你想输出一个新行时。
关于formatting - Format.fprintf 中框的缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35275033/
在我的 C++ 代码中有几个 fprintf 语句,我已将其用于调试。由于我可能会再次需要它们,所以我暂时不想将它们注释掉。但是,我需要快速执行程序,所以我想避免它们被打印出来,因为它们目前是这样的(
巧合的是,我发现 disp(fprintf()) 打印了 fprintf 的字符串加上它所具有的字符数。我知道,disp() 是多余的,但出于纯粹的好奇心,我想知道为什么它会打印字符数,因为这可能有一
我正在运行一些基准测试以找到用 C++ 将巨大数组写入文件的最有效方法(在 ASCII 中超过 1Go)。 所以我将 std::ofstream 与 fprintf 进行了比较(参见下面我使用的开关)
假设我有两个线程将某些内容(相对较长)打印到 stderr 或 stdout,这两个流的函数是线程安全的,因为它们永远不会“交错”字符?因此,例如,如果我有“Hello, World”,我将永远不会得
我的应用程序(用 C 语言编写)必须将 500 个字符串出队并将它们写入文本文件。我可以将每个字符串出列并使用单独的 fprintf 语句将每个字符串写入一个文件,或者我可以将所有出列的字符串连接成一
我是编程新手,一开始试图用链表构建堆栈。 但是在打印列表中包含的元素时,fprintf()不起作用。 这是我的代码: #include #include //define stack and fu
我正在尝试代表一款战斗卡牌游戏: typedef struct list_of_cards* p_loc; typedef struct game game_s; struct list_of_car
我正在尝试使用以下 C 代码打印出我传入的数组。它应该以十六进制格式输出文本,每行一个,打开文件没有问题。当我第一次写它时,我的工作没有问题,我打开了输出文件,我的数组就在那里。我换了fileOutN
我正在尝试代表一款战斗卡牌游戏: typedef struct list_of_cards* p_loc; typedef struct game game_s; struct list_of_car
在我的代码中,fprintf 通过返回在 STREAM 中写入的字节数成功返回,但在实际文件中,我写入的字符串不存在。 最佳答案 输出可能只是经过缓冲。尝试使用 close() 关闭文件或在流上调用
我正在测试 fprintf() 的用法,但它不起作用。当我第一次编写代码时,我忘记在 fprintf() 中添加 \n 并且它起作用了。但是,当我在“test 1 2”的开头添加 \n 时,它停止了工
我正在开发一个生成 FDF 文件以填写 Adobe PDF 表单的程序。目前,我有各种被调用的过程,在每个过程终止之前,它打开 FDF 文件,写入其特定数据,然后关闭文件。 我试图将用于将数据写入
假设我有一个随机变量 a=1.2400 ,我想用四位有效数字打印它,即 1.240。我该怎么做? fprintf('%0.4g',a) % drops rightmost zero fprintf('
我真的需要一些帮助,我已经为此花了 6 个小时,我觉得我已经尝试了我能做的一切。这是我需要做的: 我需要将星号金字塔打印到 C 语言中的 triangle2.txt 文件中。 我知道我里面的代码将创建
C - fprintf 没有写入文件,知道为什么吗? #include #include int main(void){ FILE* pfile=fopen("/home/user-vla
如何在文件末尾为 fprintf() 用户输入的文本创建一个新行?我现在的代码是这样的: #include #include int main() { int lines; int
我的代码当前正在消耗日志文件输出的字符,但我不知道确切原因。 FILE* theLog; char filename[150]; theLog = fopen(filename, "w"); fpri
我正在尝试显示以下内容 static const char MSG[] = "Test %ld\n"; static int COUNT = 5; fprintf(stdout, "%s", MSG,
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
在下面的代码中,我尝试从套接字读取并将结果存储在文件中。 实际发生的情况是,我的客户端向我的服务器发送了一个 file.html 的 GET 请求。我的服务器找到该文件并将其内容写入套接字。最后,我的
我是一名优秀的程序员,十分优秀!