External File access Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eddie Sand
    New Member
    • Oct 2007
    • 3

    External File access Question

    I'm attempting to get a commercial adaptation of a rail traffic-control simulation model to interact with a home-brewed program duplicating the dispatcher's thinking, previously written (without any I/O interface) in BASIC a few years ago, now being redeveloped in C++.

    I've been learning C++ for a couple of months; have no problem with commonly-used programming functions, what little I've scraped off the 'Net makes a reference to "high-level file access"; we could use a reference more attuned to general orientation if anyone can suggest one.

    The commercial program has a fully-developed external I/O interface using a set of text files which reside in the same folder as the application (O/S is Windows XP Pro).

    I can generate commands, which should cause changes in settings on the commercial application when recognized, but am not familiar with the technique to enter them on the input file, which apparently can't be relocated to my program.

    UPDATE

    Since the previous post I have been able to send text to the destination file, but only when that file resides on a 3.5" diskette.

    Attempts to re-orient the output to a file on the hard disk by changing the destination from 'c' to 'a' were unsuccessful, whether the destination file resides in a separate folder or not

    To further elaborate:

    the command

    outFile.open ("a:mydata.out" );

    will write the text specified as "mydata" to a diskette

    But the command

    outFile.open ("c:mydata.out" };

    won't create similar output on the hard disk, nor will the command

    outFile.open {"c:myfolder/mydata.out);

    write that output to a specified folder

    the only preprocessor direcives in use are "iostream","fst ream" and "iomanip", if this is a factor.

    Thank you for your help
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    If you are using an fstream, you must open it as an injout or ouput file. And , if output, say where the writing starts. At the beginning?? Appended to the end??

    Also, if you have in input file, then it cannot be created. If it was, then it would be an output file.

    You might post a little more of your code.

    Comment

    • Eddie Sand
      New Member
      • Oct 2007
      • 3

      #3
      Thank you for pointing me in the right direction; I'll add some more specific details.

      The program is structured as follows, with actual starements numbered (CAPITALIZED TEXT does not represent actual code)

      //PREPROCESSOR INFO//
      //NAMESPACE//
      //MAIN//

      (1) infstream inFile;
      (2) ofstream outFile;

      declare/create files

      (3) inFile.open ("a.testa.txt") ;
      (4) outfile.open ("a.results.out ");

      open I/O files

      (5) outFile<<fixed< <showpoint;
      (6) outFile<<setpre cision(2);

      decimal manipulators

      (7) outFile<<"LABEL "<<SAMPLEID<<en dl;
      (8) outFile<<"LABEL "<<INPUTDATA<<e ndl;

      repeats/verifies inputted data

      //CALCULATION OF OUTPUTTED DATA//

      (9) outFile<<"LABEL "<<RESULTS<<end l;

      writes calculated value to file

      (10) inFile.close();
      (11) outFile.close() ;

      closes files

      //END OF PROGRAM STRUCTURE//

      As originally written above, the program read data from a diskette and wrote the results to that diskette as an OUT file.

      When an empty NotePad text file, designated 'results' was prepositioned on the diskette and specified as above, the program had no difficulty writing to the file.

      However, when the same flie was moved to the hard disk and the code changed to 'outFile.open(" c.results.out") ', no output of any kind was generated, whether the destination file 'results' resided in a separate folder or not.

      multiple 'outFile.open' statements to both 'c' and 'a' also generated no output.

      The files appear to open and close normally, so it would appear that the issue requires further specification of the file stream variables, associating them more directly with the I/O sources/devices.

      The destination text file must reside in the same folder as the application for which it is intended, and is "wiped clean" every time new input is sent.

      Again, my thanks for any help you can offer.

      regards, Eddie Sand

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You may have to specify the path to the file when you open it.

        You may have to specify where the reading or writing is to start. There are defaults that may not be the ones you want.

        The location of the file does not affect reading or writing.

        Comment

        • RRick
          Recognized Expert Contributor
          • Feb 2007
          • 463

          #5
          Have you tried adding the root '\' to the file name? You will need this for the path name.

          Instead of using C:xxx use C:\xxx.

          Comment

          • Eddie Sand
            New Member
            • Oct 2007
            • 3

            #6
            Thanks to you both; the missing slash turned out to be the answer. I'm sure I'll have more issues as this project advances.

            HISTORICAL FOOTNOTE:

            Until the development of the higway and air networks after World War II, there was a small market for fiction centered around the railroads. Eddie Sand, a creation of Saturday Evening Post stringer Harry Bedwell, was probably the best-remembered fictional character from that era, an itinerant "boomer" telegraph operator in the mold of Hemmingway's Nick Adams.

            Comment

            Working...