Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > ISO C++ forbids declaration of `cout' with no type.

Reply
Thread Tools

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

 
 
Penn
Guest
Posts: n/a
 
      01-09-2006
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.

 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      01-09-2006
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-lit...t.html#faq-5.8

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

Good luck.

Best regards,

Tom

 
Reply With Quote
 
 
 
 
Penn
Guest
Posts: n/a
 
      01-09-2006
Ah, i see. Thank you for your help, most usefull.

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-09-2006

"Penn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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


 
Reply With Quote
 
=?ISO-8859-1?Q?Sch=FCle_Daniel?=
Guest
Posts: n/a
 
      01-09-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"ISO C++ forbids declaration of uchar with no type" aneuryzma C++ 8 07-02-2008 02:09 PM
codecvt.cc:39: error: ISO C++ forbids declaration of`_RWSTD_NAMESPACE_BEGIN' with no type wong_powah@yahoo.ca C++ 7 02-05-2008 05:22 PM
ISO C++ forbids declaration of 'Rectangle' with no type Florian Haag C++ 7 01-24-2007 10:08 PM
ISO C++ forbids declaration of 'vector' with no type gamehack C++ 3 02-13-2006 05:09 PM
ISO C++ forbids declaration of "tst" with no type Henrik S. Hansen C++ 2 05-02-2004 08:38 PM



Advertisments