Thread: Filesystem C++

  1. #1
    Registered User
    Join Date
    May 2008

    Filesystem C++

    Help me with this:
    I wanted to make a program where it allows me to open and add new Data by just a console program.

    #include <ofstream>
    #include <iostream>
    // Run
    int main ()
    // We assign the stream library to var stm
    ofstream stm; // Do I need to make this a pointer???
    // My vars/pointers
    char FILE;
    char CONTENT;
    int  IF_REMOV_TRUE;
    // Input the file specified to open it
    std::cin >> FILE;; // Open
     if (stm != NULL) // Checks to see if its not working
    	 // Allows the user to add content
    	 std::cin >> CONTENT;
    // I was going to add remove but I need help with the current error.
     std::cin >> IF_REMOV_TRUE;
     return 0;
    My Compiler comes back with this:
    Cannot open include file: 'ofstream': No such file or directory

    I'm using Visual Studio 08
    Last edited by bobbelPoP; 06-24-2008 at 06:25 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Use <fstream>.

    Then, remember that the ofstream class belongs to the std namespace (as does cin).

    Then realize that a char is a variable that holds only a single character, so it won't hold a filename. You want std::string inside <string>. (You'll have to use FILE.c_str() to pass it as the filename to open, though.)

    You should generally write only a little bit of code at a time, then compile it and make sure it does what you expect. This is too much code with too many errors to be compiled for the first time. I'd start with an empty main and add a few things at a time.
    Last edited by Daved; 06-24-2008 at 06:56 PM.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Incidentally, this thread is continued at Evil. You may wish to read it for further insight.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Filesystem questions
    By Drogin in forum Tech Board
    Replies: 4
    Last Post: 04-13-2009, 11:59 AM
  2. NTFS ( FileSystem ) with C++
    By bobbelPoP in forum Windows Programming
    Replies: 1
    Last Post: 07-19-2008, 02:34 PM
  3. Need to know the filesystem on /dev/sda1
    By amit_sahrawat in forum Linux Programming
    Replies: 7
    Last Post: 12-13-2007, 05:29 AM
  4. Filesystem monitoring question
    By rools in forum Linux Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 PM
  5. Replies: 3
    Last Post: 09-01-2005, 11:47 AM