Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1955 Cannot compile \\n as the characters \ and n.

OTHER
closed
nobody
Support
none
Unknown
False
2013-04-20
2013-04-19
andrew dolan
No

I am using minGW with Eclipse Juno CDT package on Windows 7 64. I am having a compilation problem. I put in this code:

    cout << "Use \\n to cause a newline; use \\t to cause a tab." << '\n';
    cout << "Use \\a to cause a beep (only on some platforms)!";

or this code

    printf("Use \\n to cause a newline; use \\t to cause a tab.\n");
    printf("Use \\a to cause a beep (only on some platforms)!\n");

Here is the problem. The \n or \a or \t does not get compiled as the two characters \ and n or \ and t or \ and a. Instead they get compiled as \n, and \a, and \t. This is the same whether I run it in the command line or on the debugger in eclipse. When I try just \ it correctly compiles it as . It is almost like the compiler takes the \ and compiles it into a \ and then compiles the \ and the n together, for example, as a \n which is a carriage return.

Any help is much appreciated.

thanks!

Discussion

  • Earnie Boyd
    Earnie Boyd
    2013-04-20

    • labels: \n, \a, \t, printing special characters in C or C++ --> printing special characters in C or C++
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,13 +1,15 @@
     I am using minGW with Eclipse Juno CDT package on Windows 7 64.  I am having a compilation problem.  I put in this code:
    
    +~~~~~~
         cout << "Use \\n to cause a newline; use \\t to cause a tab." << '\n';
         cout << "Use \\a to cause a beep (only on some platforms)!";
    -
    +~~~~~~
     or this code
    
    +~~~~~~
         printf("Use \\n to cause a newline; use \\t to cause a tab.\n");
         printf("Use \\a to cause a beep (only on some platforms)!\n");
    -
    +~~~~~~
     Here is the problem.  The \\n or \\a or \\t does not get compiled as the two characters \ and n or \ and t or \ and a.  Instead they get compiled as \n, and \a, and \t.  This is the same whether I run it in the command line or on the debugger in eclipse.  When I try just \\ it correctly compiles it as \.  It is almost like the compiler takes the \\ and compiles it into a \ and then compiles the \ and the n together, for example, as a \n which is a carriage return.
    
     Any help is much appreciated.
    
    • status: open --> closed
     
  • Earnie Boyd
    Earnie Boyd
    2013-04-20

    Please discuss this on the mingw-users list. See http://www.mingw.org/lists.shtml for instructions to sign-up for the list.