ifstream question

This is a discussion on ifstream question within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Dave_Sinkula SOP, often. Perhpas something like this: You have your source in one directory. It builds the ...

  1. #16
    Registered User
    Join Date
    Oct 2006
    Posts
    8
    Quote Originally Posted by Dave_Sinkula
    SOP, often. Perhpas something like this:

    You have your source in one directory. It builds the relocatable object files into a subdirectory (often), and places the resulting executable there as well. When it runs the executable, it runs it from where the "project directory" is (maybe not where the executable was put, and which may be different from where the source code is).

    Happens all the time.

    Drives you mad sometimes.


    The short version is to run the code from an actual command shell.
    Kind of makes sense. Thanks, mucho for that.

    Still not sure why the original wouldn't run without the absolute path. But. Eh, well. New one works like a charm. Maybe I borked something elsewhere in the code.

  2. #17
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Quote Originally Posted by Dekon
    Kind of makes sense. Thanks, mucho for that.

    Still not sure why the original wouldn't run without the absolute path. But. Eh, well. New one works like a charm. Maybe I borked something elsewhere in the code.
    Because often the current working directory of the program is not the directory the program resides in.

    E.g. in Visual C++ the default is to put the executables into either:

    My Documents\My Visual Studio Projects\ProjectName\Debug\
    or
    My Documents\My Visual Studio Projects\ProjectName\Release\

    but the IDE starts the program with a working directory of
    My Documents\My Visual Studio Projects\ProjectName\


    You can always set the working directory yourself by making a shortcut and telling the shortcut what directory you want.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    In other words, don't be deluded into thinking that relative paths have even the faintest relation to where the executable actually is. There is, in fact, no standard way of finding out where the executable is.

    Relative paths are always in relation to the current working directory, which is freely adjustable: by links to the program, by calling from a specific directory in the shell, by passing the right parameters to CreateProcess.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Each exe during run has a "current directory" which may not be the directory where the exe is located.

    IDe should have a possibility to specify the "Current directory"

    Have you tried to create a file instead of reading from the existing file and see where the file is created with the specified name in each case (when running from the IDE and from the prompt). In most cases the location - where file is created is the location where your exe looks for file to be opened.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. Simple ifstream Question
    By Paul22000 in forum C++ Programming
    Replies: 8
    Last Post: 12-05-2008, 05:34 PM
  3. question about ifstreams
    By Amyaayaa in forum C++ Programming
    Replies: 6
    Last Post: 05-27-2008, 04:48 PM
  4. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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