Manipulation of Files:

This is a discussion on Manipulation of Files: within the C++ Programming forums, part of the General Programming Boards category; I am writing a large program (by my standards but certainly not by most) for school. Anyway, in both of ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Manipulation of Files:

    I am writing a large program (by my standards but certainly not by most) for school. Anyway, in both of my classes (that is the abstract data type, not school) I am manipulating files. Is there anyway that I can use a variable to connect the filestream to the directory file. I have tried using a string variable in declarations similar to the following:
    ifstream inFstream;
    inFstream.open(filename) //filename is a string

    I get compile errors because it wants a constant value. Is there a workaround. I am hoping it is like dynamic arrays and there is a pretty simple answer.

    Also, still on the topic of files. How can I goto a specific part of a file and manipulate it? The end of a file?

    I learn best from examples but I'm definatatly a newbie at c++ so if you could tone down examples to something human it would be appreciated.

    Thanks for any help you can provide:
    retretret

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    if you are asking to open a file then this is how i do it..

    ----
    char filename[12];
    ifstream fin;

    cout<<"enter file name : ";
    cin.getline(filename,12,'\n');

    fin.open(filename);
    ----

    >>How can I goto a specific part of a file and manipulate it? The end of a file?

    use eof command to detect the end-of- file
    or the seekg comman

    fin.seekg(30); --> goes to the byte# 30 in the file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. XP/Vista - renaming, moving & deleting files
    By Tigers! in forum Windows Programming
    Replies: 4
    Last Post: 06-28-2009, 05:21 PM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM

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