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
    22,264
    Because you should escape your backslashes within a string literal, e.g.,
    Code:
    ifstream a_file ( "D:\\ LotteryProgram / MegaMill" );
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,438
    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 05: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, 03: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, 03:17 AM
  3. Escape Key
    By mrafcho001 in forum Windows Programming
    Replies: 1
    Last Post: 11-10-2005, 04:51 PM
  4. Can you escape ...
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 04-28-2005, 11:25 AM
  5. escape sequence
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 08-01-2002, 09:36 AM

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