C++ (g++) 特殊字符编码('\a'、'\b'等)

C++ (g++) special characters encoding ('\a', '\b', etc.)

我在 Linux Mint.

上使用 g++ 版本 4:4.8.2-1ubuntu6 和 Eclipse 3.8

我的 C++ 书中的以下示例无法按预期工作:

//bondini.cpp -- using escape sequences
#include <iostream>
int main()
{
    using namespace std;
    cout << "\aOperation \"HyperHype\" is activated\n";
    cout << "enter sercret code:________\b\b\b\b\b\b\b\b";
    long code;
    cin >> code;
    cout << "\aYou entered: " << code << "...\n";
    cout << "\aCode OK! Commencing Z3!\n";
return 0;
}

当 运行 程序时,我得到以下结果:

在 Eclipse 和目录中,我使用的是 UTF-8 编码。为什么 '\a' 不能正常播放声音,'\b' 不能将光标向后移动 space,而 '\n' 可以正常工作。

edit:据我了解,是编译器弄的一团糟。 --> 我错了,在终端中它工作正常,但是 eclipse 'terminal' 不工作。

无论您将输出发送到哪里。目的地用它做什么完全掌握在自己手中。因此,虽然 Eclipse 可能不支持您的终端应该支持的这些特殊字符。