fstream question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan M

    #1

    fstream question

    When you specify the file for an fstream inside your code, do you refer
    directly to the files location?

    e.g. c:\file

    or do you just place the file to be read in the same folder as the .cpp
    file?

    I'm trying to read in some data in a file and the resources I have looked at
    do not give me this information.

    Thank you so much

    Dan M


  • Karl Heinz Buchegger

    #2
    Re: fstream question

    Dan M wrote:[color=blue]
    >
    > When you specify the file for an fstream inside your code, do you refer
    > directly to the files location?
    >
    > e.g. c:\file
    >
    > or do you just place the file to be read in the same folder as the .cpp
    > file?
    >[/color]

    Depends on the file content.
    If it is some vital and relatively constant information, such as eg. some
    program settings, I use argv[0] to determine the path to the executable
    (if argv[0] provides this, there is no guarantee for that) and use that
    path to build the complete filename.

    If the file contains user data, I let the user specify which file he wants
    to process. Most operating systems provide a way to have some sort of
    utilities directory, where programs can be started easily from. The
    users data file needs not to reside on this directory.

    --
    Karl Heinz Buchegger
    kbuchegg@gascad .at

    Comment

    • lallous

      #3
      Re: fstream question

      Hello
      [color=blue]
      > When you specify the file for an fstream inside your code, do you refer
      > directly to the files location?
      >
      > e.g. c:\file
      >
      > or do you just place the file to be read in the same folder as the .cpp
      > file?
      >
      > I'm trying to read in some data in a file and the resources I have looked
      > at do not give me this information.
      >
      > Thank you so much
      >[/color]

      You can refer to the file either in a relative manner or absolute manner,
      either method works.
      If you want your code to work, it is better to address files in a relative
      manner, either relatively to the current directory or some directory one
      level above it, such as: ./prog.exe and ./data./*.txt (your data files).

      Regards,
      Elias


      Comment

      • Sumit Rajan

        #4
        Re: fstream question

        Dan M wrote:[color=blue]
        > When you specify the file for an fstream inside your code, do you refer
        > directly to the files location?
        >
        > e.g. c:\file
        >
        > or do you just place the file to be read in the same folder as the .cpp
        > file?
        >
        > I'm trying to read in some data in a file and the resources I have looked at
        > do not give me this information.[/color]

        You may like to read this:


        Regards,
        Sumit.
        --
        Sumit Rajan <sumit DOT rajan AT gmail DOT com>

        Comment

        Working...