Thread: need help with cout & output

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    need help with cout & output

    I don't understand what these errors mean & i don't know why "cout" is not defined.

    line 9 is: aLabel.output(cout);
    I have the same error messages for line 10.
    line 10 is: client.output(cout);

    for client the input is MailingLabel client("Joe Smith", "Newark, DE", 19711);

    "mail.cc", line 9: Error: cout is not defined.

    "mail.cc", line 9: Error: Formal argument 1 of type std::basic_ostream<char, std::char_traits<char>>& in call to MailingLabel:utput(std::basic_ostream<char, std::char_traits<char>>&) const is being passed int.

  2. #2
    Registered User programmer's Avatar
    Join Date
    Oct 2001
    Posts
    22

    Question

    Post your code plz !!

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    here's my code

    Here's my code:

    Script started on Sun Dec 02 14:41:58 2001
    strauss.udel.edu% cat mailinglabel.h

    //Programmer: Christine Jacksson

    //Date:

    //Section:

    //header file for mailinglabel class



    #ifndef MailingLabel_H

    #define MailingLabel_H



    #include <iostream>

    using std :: ostream;



    class MailingLabel {

    public:

    MailingLabel(); //default constructor

    MailingLabel(const char*, const char*, int); //class constructor

    //MailingLabel(MailingLabel&); //copy constructor

    //~MailingLabel(); //class destructor

    MailingLabel& operator=(const MailingLabel&); //overloaded

    //assignment operator

    void output(ostream&) const; //print out to a file

    //void input(istream&); //get input from a file

    private:

    char *name;

    char *address;

    int zipcode;

    };

    #endif

    strauss.udel.edu% cat mial   ali  ilinglabel.cc

    //member functions for mailinglabel class

    //class implementation part I of lab



    #include "mailinglabel.h"

    #include <iostream>

    using std :: endl;

    using std :: ostream;



    MailingLabel :: MailingLabel () {

    name = NULL;

    address = NULL;

    zipcode = 0;

    }

    MailingLabel :: MailingLabel(const char *n, const char *a, int z) {

    name = new char[strlen(n) + 1];

    strcpy(name, n);



    address = new char[strlen(a) + 1];

    strcpy(address, a);



    zipcode = z;

    }

    void MailingLabel :: output(ostream &m) const{

    m << name << endl;

    m << address << endl;

    m << zipcode << endl;

    }





    strauss.udel.edu% cat mailinglabel.          l.cc

    //main program for class implementation pt. I



    #include "mailinglabel.h"

    int main() {

    MailingLabel aLabel;



    MailingLabel client("Joe Smith", "Newark, DE", 19711);



    aLabel.output(cout);

    client.output(cout);

    }

    strauss.udel.edu% CC ami   mailinglabel.cc maill .cc

    mailinglabel.cc:

    mail.cc:

    "mail.cc", line 9: Error: cout is not defined.

    "mail.cc", line 9: Error: Formal argument 1 of type std::basic_ostream<char, std::char_traits<char>>& in call to MailingLabel:utput(std::basic_ostream<char, std::char_traits<char>>&) const is being passed int.

    "mail.cc", line 10: Error: cout is not defined.

    "mail.cc", line 10: Error: Formal argument 1 of type std::basic_ostream<char, std::char_traits<char>>& in call to MailingLabel:utput(std::basic_ostream<char, std::char_traits<char>>&) const is being passed int.

    4 Error(s) detected.

    strauss.udel.edu% exit

    strauss.udel.edu%
    script done on Sun Dec 02 14:42:44 2001

  4. #4
    Registered User programmer's Avatar
    Join Date
    Oct 2001
    Posts
    22

    Red face

    Now do'nt take this bad, but i gotta tell ya this .... beleive me i can'nt understand yur code at all ... it looks easy, but gotta get a little orgranized ... i dunno where the head is going and where the tail ....
    sorry.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    You're welcome to try these ideas, some may work, others may not.

    1) add line: #include <iostream> in main program.


    2) +/-: delete the line #include <iostream> in MailingLabel.h

    3) +/-: delete the line using std:stream in MailingLabel.h

    4) in MailingLabel.cpp add #include <cstring>//I think that's where strcpy() is.

    5) aLabel is declared with the default constructor which sets the two char * to NULL. Yet you try to output them with the call to aLabel.output(cout); I would probably declare memory with new, and then assign string copy an empty string into them rather than NULL. Then the function call will work and the default constructor is more consistent with the non-default constructor.

    6) If you use dynamic memory I think you should delete it too. This should be done in the destructor.

    7) If you pass output the ostream object cout then output will go to the standard output, which is usually the monitor screen. If you want the output to go to a file then you need to declare an ofstream (or fstream) and associate it with a file before using stream methods lik << . You can deal with getting the ofstream ready in the section of code in main() dealing with variables and then pass it as you do cout or you can set up the ofstream in the output function per se and use it from there. To use ofstreams/ifstreams/fstreams you need to add the line #include <fstreams> in the appropriate cpp file.

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Cool What compiler......

    What compiler are you using??? (just wondering)
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Spying" on cout
    By sirjis in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2006, 05:00 PM
  2. Compiles but won't cout?
    By Kayoss in forum C++ Programming
    Replies: 2
    Last Post: 05-15-2006, 01:27 PM
  3. Problem with cout
    By kristentx in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2006, 12:37 PM
  4. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM
  5. changing cout output
    By Yohumbus in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2002, 04:09 AM