Question about file I/O

This is a discussion on Question about file I/O within the C++ Programming forums, part of the General Programming Boards category; Im curious, if i want to find a file on my c: say its a txt file named hello.txt. Is ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    14

    Question about file I/O

    Im curious, if i want to find a file on my c: say its a txt file named hello.txt. Is there any special syntax that is involved with doing so through c++? I mean can i just say open file so and so and than just do my programming after that or do i need anything else to go with it?

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    you didn't quite specify your question enough, either you are asking to have an algorithm to "search" for a file on your hard drive, or open a file from your c: drive???????


    if you want to open a file, you would have to make up your mind and decide if you want to designate this file for reading from it or writing to it....


    [CODE]

    #include <fstream.h> // you need to include this header file

    ifstream fin("c:\\TextFile.txt"); // opens a file for reading

    ..................................................


    ofstream fout("c:\\OtherTextFile.txt"); // opens a file for writing






    Hope this helps....

    Regards,
    matheo917

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    14
    Im sorry. Id like to know, how i can go about having the user enter a file and than having c search the computer(and or drives) to find it. Either that or im looking to find some tutorials that can help me with this. Id rather try to struggle with it than just have it given, kinda make me feel like i did it on my own.

  4. #4
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    to tell you the truth i don't remember of the top of my head what the template function you might use to search the c: drive...

    however, i am very sure that you can make a binary search algorith (home made one).......what you simply would do is compare file by file in the whole hard drive until you find the desired one.....

    if you want i will look around, if i will find something then i will let you know........

    unless someone else can answer this question first........

    Regards,
    matheo917

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. File i/o and ASCII question
    By muzihc in forum C Programming
    Replies: 13
    Last Post: 11-04-2008, 11:46 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 05:14 AM
  4. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 AM
  5. Another dumb question about file i/o
    By Cobras2 in forum C++ Programming
    Replies: 23
    Last Post: 03-14-2002, 04:15 PM

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