Unreconized escape character secquence

This is a discussion on Unreconized escape character secquence within the C++ Programming forums, part of the General Programming Boards category; Thanks for all your help guys; I get an "Unrecognized escape character sequence" here, Code: ifstream a_file ( "D:\ LotteryProgram ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Location
    Florida, Dade County, Homestrad, 33031
    Posts
    40

    Unreconized escape character secquence

    Thanks for all your help guys;
    I get an "Unrecognized escape character sequence" here,

    Code:
     ifstream a_file ( "D:\ LotteryProgram / MegaMill" );   //Opens MegaMill for reading the file
      
       a_file >> str; //Reads one string from the file MegaMill
    and I don't understand it. Please explain why? . . . . therry

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Because you should escape your backslashes within a string literal, e.g.,
    Code:
    ifstream a_file ( "D:\\ LotteryProgram / MegaMill" );
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,468
    If you try to use a single backslash the compiler expects an escape character like \n newline etc. So as laserlight shows you have to add the extra oblique. As an example try outputting a quoted string and see what happens, eg show this including the quotes : "Hello World"
    Last edited by rogster001; 04-07-2012 at 04:38 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Escape sequences in c
    By linuxlover in forum C Programming
    Replies: 3
    Last Post: 11-03-2010, 02:39 PM
  2. Annoying Escape Character Squares in Notepad
    By firetheGlazer in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 07-18-2008, 02:17 AM
  3. Escape Key
    By mrafcho001 in forum Windows Programming
    Replies: 1
    Last Post: 11-10-2005, 03:51 PM
  4. Can you escape ...
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 04-28-2005, 10:25 AM
  5. escape sequence
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 08-01-2002, 08:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21