escape sequence and multi character interpretation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: escape sequence and multi character interpretation

  1. #1
    Join Date
    Mar 2011
    Posts
    153

    escape sequence and multi character interpretation

    Hi

    I believe "\" signals that the next character is to be interpreted differently than how it's normally dealt with. Can "\" only be used to signal the alternative interpretation of a signal character at a time? You see, in the code below, the statement in red gives rise to problem. Please help me with it. Thanks.

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
        cout << "Nancy said, \"This is backslash t, \t, OK\"" << endl;
        cout << "Nancy said, \"This is backslash t, \\t, OK\"" << endl;
    
        cout << "feet" << "\'-" << "inches" << "\"" << endl;
        cout << "feet" << '\'' << "-" << "inches" << '\"' << endl;
        cout << "feet" << '\'-' << "inches" << '\"' << endl; //problem
    
        system("pause;");
        return 0;
    }

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,571

    Re: escape sequence and multi character interpretation

    Yes, it's the part in red that causes the problem, but it's not due to an invalid escape sequence. The construct in red is a multicharacter constant and evaluates to an int, and that's wat you get as output: a number. Character literals that are meant to result in a value of type char can only contain a single character (where an escape sequence counts as a single character).

    Quote Originally Posted by heights View Post
    Can "\" only be used to signal the alternative interpretation of a signal character at a time?
    I'm not sure I completely understand your question, but perhaps this is an adequate answer: An escape sequence always consists of a backslash and one other character (where the other character may be a backslash itself) except for those escape sequences specifying a hexadecimal or octal character code.

    For reference: C++ Character Constants
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    Re: escape sequence and multi character interpretation

    Yes it can only operate on a single character at a time.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  4. #4
    Join Date
    Dec 2011
    Posts
    2

    Re: escape sequence and multi character interpretation

    there are only 14 escape sequences :
    Newline \n
    Horizontal tab \t
    Vertical tab \v
    Backspace \b
    Carriage return \r
    Formfeed \f
    Alert \a
    Backslash \\
    Question mark \?
    Single quotation mark \'
    Double quotation mark \"
    Octal number \ooo
    Hexadecimal number \xhhh
    Null character \0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center