Thread: Nothing wrong!!! And yet I get this error:

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation Nothing wrong!!! And yet I get this error:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <conio.h>
     
    using namespace std;
     
    int main( void )
    {
    ofstream out_file;
    out_file.open("test1.txt");
    out_file << "This_Is_A_Test_File" << endl;
    out_file.close();
     
    return 0;
    }
    There is nothing wrong with this code, and yet:

    Quote Originally Posted by DevC++
    aggregate `std::ofstream out_file' has incomplete type and cannot be defined
    Please help, this is just like the example script that tons of other sites give too!

    Thanks, August.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Code:
    #include <fstream>
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    lol, nothing wrong

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks Brain, I would have used WriteFile() to do this job, but I am making a pure DOS program. Why don't the examples have you include <fstream>?

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What examples?

    On some platforms you might get unlucky and the original code might work. However, whoever wrote the examples you speak of shouldn't have relied on that, since it is not guaranteed to work on all platforms. Basically, whenever you use a specific function, class or object from a library, you should explicitly include the header that declares it. You can almost always find out which header it is from your favorite library documentation.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Cool-August
    I am making a pure DOS program.
    No you are not. You are writing a console program. DOS is a generic term that means "Disk Operating System", which is used by MS-DOS, MS-Windows, Unix, Linux, VAX, VMS, Crey, MAC or another other operating system that interacts with a hard drive, floppy disk drives, CD rom drives, RAM drives, and tape drives.
    Last edited by Ancient Dragon; 01-10-2006 at 12:52 PM.

  7. #7
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    You are right, I am just making a program for a system that only has MS-DOS on it, and the console.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    <fstream> is for the file streams. <iostream> is for the generic stream classes and the console streams cout, cin and cerr.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Cool-August
    You are right, I am just making a program for a system that only has MS-DOS on it, and the console.
    what version os MS-DOS ? Version 6.X or earlier. Then you need a 16-bit compiler with probably will not support <fstream> because most of those compilers are too old.

Popular pages Recent additions subscribe to a feed