gpt4 book ai didi

c - Perl(或C printf)后退一个选项卡,可能吗?

转载 作者:行者123 更新时间:2023-11-30 19:56:52 24 4
gpt4 key购买 nike

我们都知道如何使用\t 进一步打印字符串

printf ("Hello\tthere!\n");

输出:

Hello    there!

向后打印一个选项卡怎么样?我知道我们可以使用\r 从行的开头开始,但是在某些情况下缩进比这更复杂,我正在寻找类似\bt (如果存在)这样的东西,这样我可以写:

printf ("Hello\tthere! \n\tHow\n\btare you?\n");

获取输出:

Hello    there!
How
are you?

编辑

我对这里回复的数量和速度感到惊讶,有时甚至对一些评论的无用性感到惊讶,但只有少数。我想要实现的目标当然比这更复杂,它正确地格式化 XML 文件以使其易于阅读。我想确定没有更简单的方法,回复确认没有,谢谢。

编辑2

抱歉,大家否决这个问题是正确的,首先是因为我没有指定我正在写入文本文件,其次是因为我假设选项卡可以被文件处理程序“记住”。抱歉浪费您的时间。

最佳答案

使用printf,您可以显式控制进行制表操作的次数。要返回选项卡,您只需使用更少的选项卡即可。从您提供的示例来看,您似乎希望记住选项卡级别,并且如何缩进比打印时实际缩进的距离更远。它会出现在与那里!是你吗?

相同的制表位处

假设:

printf ("Hello\tthere! \n\tHow\n\btare you?\n");

您期望看到:

Hello   there!     Howare you?

Then just don't add the tab before are you? and you will get what you want. To get fewer tabs, just add fewer \t symbols to your printf. printf doesn't have any memory of what tabbing has occurred before.

printf ("Hello\tthere! \n\tHow\nare you?\n");

关于c - Perl(或C printf)后退一个选项卡,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13936875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com