ISO C++ forbids declaration of `cout' with no type.

Discussion in 'C++' started by Penn, Jan 9, 2006.

  1. Penn

    Penn Guest

    Hello, I'm new to C++ and while I was playing around with one of my
    ideas I stumbled uppon the error message I used as a subject for this
    topic.
    My question to you out there is how can i make this part of the code
    work :

    class PwCheck
    {
    public:
    string x;

    cout<< "Type in the Pw:\t" <<endl;
    cin>> x;
    cin.ignore();

    Thank you in advance for any helpfull answers.
     
    Penn, Jan 9, 2006
    #1
    1. Advertising

  2. Penn wrote:
    > Hello, I'm new to C++ and while I was playing around with one of my
    > ideas I stumbled uppon the error message I used as a subject for this
    > topic.
    > My question to you out there is how can i make this part of the code
    > work :
    >
    > class PwCheck
    > {
    > public:
    > string x;
    >
    > cout<< "Type in the Pw:\t" <<endl;
    > cin>> x;
    > cin.ignore();
    >
    > Thank you in advance for any helpfull answers.


    Two suggestions.

    (1) Please get a copy of Accelerated C++ by Koenig & Moo. Ask this
    question again after you've read that book.

    (2) In any case, you will find the following item from the C++ FAQ
    helpful in getting helpful answers to your questions:

    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    I suspect you may find the rest of the FAQ quite helpful as well.

    Good luck.

    Best regards,

    Tom
     
    Thomas Tutone, Jan 9, 2006
    #2
    1. Advertising

  3. Penn

    Penn Guest

    Ah, i see. Thank you for your help, most usefull.
     
    Penn, Jan 9, 2006
    #3
  4. Penn

    Mike Wahler Guest

    "Penn" <> wrote in message
    news:...
    > Hello, I'm new to C++ and while I was playing around with one of my
    > ideas I stumbled uppon the error message I used as a subject for this
    > topic.
    > My question to you out there is how can i make this part of the code
    > work :
    >
    > class PwCheck
    > {
    > public:
    > string x;
    >
    > cout<< "Type in the Pw:\t" <<endl;
    > cin>> x;
    > cin.ignore();


    Forgot closing brace and semicolon:

    };

    Executable statements (e.g. your 'cout' and 'cin' lines)
    are only allowed inside a function body. The above is
    not a function, but a class definition.

    -Mike
     
    Mike Wahler, Jan 9, 2006
    #4
  5. Penn wrote:
    > Hello, I'm new to C++ and while I was playing around with one of my
    > ideas I stumbled uppon the error message I used as a subject for this
    > topic.
    > My question to you out there is how can i make this part of the code
    > work :
    >
    > class PwCheck
    > {
    > public:
    > string x;
    >
    > cout<< "Type in the Pw:\t" <<endl;
    > cin>> x;
    > cin.ignore();
    >
    > Thank you in advance for any helpfull answers.


    C++ is not dynamic language

    it would be ok in Python

    >>> class X:

    .... print "constructing X class"
    .... def __init__(self):
    .... print "constructing instance from X"
    ....
    constructing X class
    >>> x = X()

    constructing instance from X
    >>>


    it would be ok in Ruby

    irb(main):097:0* class X
    irb(main):098:1> puts "constructing class X"
    irb(main):099:1> def initialize
    irb(main):100:2> puts "constructing instance from X"
    irb(main):101:2> end
    irb(main):102:1> end
    constructing class X
    => nil
    irb(main):103:0> x = X.new
    constructing instance from X
    => #<X:0x402126bc>
    irb(main):104:0>


    but in C++ things inside a class are not "executable" as compiler sees
    them (well methaprogaming with templates excluded)

    all you can put in a class is objects and methods
    and each can be one of public, protected and private
    it affects its visibility and accessability

    so simple class would look like

    class X
    {
    public:
    void run();
    int x;
    private:
    void doit() { // here you can add you cout }
    int y;

    }; // << don't forget ;

    void X::run()
    {
    // here you should add you code ...
    std::cout << "print me" << std::endl;
    }

    hth, Daniel
     
    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Jan 9, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik S. Hansen
    Replies:
    2
    Views:
    51,482
    Alf P. Steinbach
    May 2, 2004
  2. gamehack
    Replies:
    3
    Views:
    8,127
    gamehack
    Feb 13, 2006
  3. Florian Haag
    Replies:
    7
    Views:
    881
    Florian Haag
    Jan 24, 2007
  4. Replies:
    7
    Views:
    852
    red floyd
    Feb 5, 2008
  5. aneuryzma
    Replies:
    8
    Views:
    1,102
    Puppet_Sock
    Jul 2, 2008
Loading...

Share This Page