Thread: SearchWay to a File

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    SearchWay to a File

    Is it possible to do a searchway to a file. This code below works if ABC.txt is in the debug folder.

    Code:
    ifstream File ("ABC.txt");

    I am trying this and have my file under C:\ but this doesn´t work.
    Is it possible in any way ?:
    Code:
    ifstream File ("C:\ABC.txt");

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Perhaps...
    Code:
    ifstream File ("C:/ABC.txt");
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    Yeah... I tried this also and it worked. 2 \\ was needed.

    Code:
    ifstream File ("C:\\ABC.txt");

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I believe you need to double the backslashes: \\, after the C:.
    Reason is that the backslash itself, is an escape character.

    (C:\\ABC.txt"), should do it.

    ACK! Too slow.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Coding View Post
    Yeah... I tried this also and it worked. 2 \\ was needed.
    FWIW: http://groups.google.com/group/comp....98ee84edda2c0?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    That was good to know so the \\ is ´safer´ than the /

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, Windows API supports "/", by converting them to "\". However, it's not clear how long that will last.
    And, of course, due the the filesystem using "\" instead of "/", using "/" outside the API won't work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM