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

P

Penn

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.
 
T

Thomas Tutone

Penn said:
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
 
M

Mike Wahler

Penn said:
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
 
?

=?ISO-8859-1?Q?Sch=FCle_Daniel?=

Penn said:
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
.... print "constructing X class"
.... def __init__(self):
.... print "constructing instance from X"
....
constructing X class
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top