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

标签 c++ eclipse linux-mint g++4.8

我在 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;
}

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

output here

在 Eclipse 和目录中,我使用 UTF-8 编码。为什么 '\a' 没有按应有的方式播放声音,并且 '\b' 没有将光标向后移动一格,而 '\n' 却可以正常工作。

编辑:据我了解,是编译器搞砸了。 --> 我错了,在终端中它工作正常,但 eclipse 'terminal' 不起作用。

最佳答案

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

关于C++ (g++) 特殊字符编码 ('\a' 、 '\b' 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38169124/

相关文章:

c++ - ofstream 输出字符串/字符而不是 double

java - 用于 mac 分发的捆绑 java 应用程序

java - 对于动态变化的元素,哪个定位器的跨浏览器可靠率更高以及为什么: cssSelector or Xpath?

linux - 无法在目录 Linux Mint Debain Mate 中复制/粘贴

linux - Linux Mint 18.3 上的 google cloud datalab 是否存在存储库引擎问题?

Eclipse 和 Hadoop 2.2 位置状态更新程序错误

c++ - 未知字符被添加到字符串的最后

c++ - clang:如何启用 ext_vector_type 的 vector 构造函数

C++ cin 在点击回车后没有返回

eclipse - Eclipse STS Grails路径问题