Search code examples
c++eclipselinux-mintg++4.8

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


I am using g++ version 4:4.8.2-1ubuntu6 with Eclipse 3.8 on Linux Mint.

Following example from my C++ book does not work as expected:

//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;
}

I get following result when running the program:

output here

In Eclipse and directory I am using UTF-8 encoding. Why does not '\a' play sound as it should and '\b' does not move the cursor one space back, while '\n' works properly.

edit: As I understand it, it is the compiler that makes the mess of it. --> I was wrong, in terminal it works fine, but eclipse 'terminal' does not work.


Solution

  • Wherever you are sending your output. What the destination does with it is entirely in its own hands. So while eclipse might not support these special characters your terminal should.