gotta love my teacher

This is a discussion on gotta love my teacher within the C++ Programming forums, part of the General Programming Boards category; given: Code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; ofstream Out("con"); //screen //Out("rect.txt"); new disk file //Oiyt("rect.txt",ios::app); #include ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    719

    gotta love my teacher

    given:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <fstream>
    
    using namespace std;
    
    ofstream Out("con"); //screen
                      //Out("rect.txt"); new disk file
                      //Oiyt("rect.txt",ios::app);
    
    #include "rect.h"
    #include "room.h"
    
    void main(int argc, char *argv[]) //notice the void
    {
         //.....
    }
    and....
    Code:
    //room.cpp
    #include "room.h"
    Room::Room(void)
    {
        Out << "Room default constructor " << endl;
    }
    in Room::Room 'Out' is undeclared. why?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    Thats a great teacher there misplaced...
    Woop?

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    so this isn't supposed to work?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    You should write "extern std::ofstream Out" at the top of the room.cpp, or declare Out in room.h. (Global variables defined in one source file must have their type declared in another file. This declaration lets the compiler know Out's type and lets the linker fill in variable Out's address.)

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Wha-what?!?!?!

    C:\Dev-Cpp\project2\room.cpp In constructor `Room::Room()':
    21 C:\Dev-Cpp\project2\room.cpp no match for 'operator<<' in 'Out << "Room default constructor "'
    error C:\Dev-Cpp\project2\rect.h:11 candidates are: std:stream& operator<<(std:stream&, const Rectangle&)

    offending line: Out << "Room default constructor " << endl;


    i supose it's refering to this in rect.h:
    friend ostream & operator <<(ostream &, const Rectangle &);
    Last edited by misplaced; 10-20-2004 at 04:18 PM.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  6. #6
    Chess Master Phanster's Avatar
    Join Date
    Oct 2004
    Posts
    8
    Maybe its a typo? Out -> cout ?

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    not a typo...in the next project we'll be writing to a file
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    I forgot to mention that you would need to have the following includes "#include <iostream>" and "#include <fstream>".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Love - learned or inherent?
    By axon in forum A Brief History of Cprogramming.com
    Replies: 42
    Last Post: 01-24-2005, 11:09 AM
  2. gotta love linker errors
    By dantestwin in forum C++ Programming
    Replies: 3
    Last Post: 07-08-2004, 05:53 PM
  3. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  4. gotta love those jaggies....*cough*
    By jverkoey in forum Game Programming
    Replies: 9
    Last Post: 04-22-2003, 08:44 PM

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