我在 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' 没有将光标向后移动一格,而 '\n' 却可以正常工作。
编辑:据我了解,是编译器搞砸了。 --> 我错了,在终端中它工作正常,但 eclipse 'terminal' 不起作用。
最佳答案
无论您将输出发送到何处。目的地如何处理它完全掌握在自己手中。因此,虽然 Eclipse 可能不支持您的终端应该支持的这些特殊字符。
关于C++ (g++) 特殊字符编码 ('\a' 、 '\b' 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38169124/