简体   繁体   English

日食; 转义序列不起作用?

[英]Eclipse; Escape Sequences don't work?

I am doing a basic C tutorial. 我正在做一个基本的C教程。 In an example this code was given to introduce escape sequences: 在一个示例中,该代码用于引入转义序列:

#include <stdio.h>

int main()
{
    printf("This is a \"sample text\"\n");
    printf("\tMore text\n");
    printf("This is getting overwritten\r");
    printf("By this, another sample text\n");
    printf("The spa \bce is removed.\n");
    return 0;
}

The console output is expected to look like this: 控制台输出应如下所示:

This is a "sample text"
    More text
By this, another sample text
The space is removed.

Instead, I get this: 相反,我得到这个:

This is a "sample text"
    More text
This is getting overwritten
By this, another sample text
The spa ce is removed.

I am using Eclipse Cpp Oxygen on Windows and the Cygwin toolchain to compile und run the code. 我在Windows和Cygwin工具链上使用Eclipse Cpp Oxygen进行编译和运行代码。 I don't know what I'm doing wrong and I thought I'd ask here for help. 我不知道自己在做什么错,我想在这里寻求帮助。

The console built in to Eclipse does not support the \\r , \\b (and \\f ) characters. Eclipse内置的控制台不支持\\r\\b (和\\f )字符。

There is a long standing bug 76936 for this which has been open for 14 years. 有一个长期存在的bug 76936 ,它已经开放了14年。 But doesn't look like being fixed. 但是看起来不像是固定的。

In linux you example works exactly as you expect. 在linux中,您的示例可以完全按预期工作。 Probably in windows the \\r is considered like \\n. 可能在Windows中,\\ r被视为\\ n。 Instead on linux terminal the \\r put (correctly) the cursor on the first char of the row. 而是在Linux终端上,\\ r将光标正确地放在行的第一个字符上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM