473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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.

Jan 9 '06 #1
4 6987
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

Jan 9 '06 #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.


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

Jan 9 '06 #3
Ah, i see. Thank you for your help, most usefull.

Jan 9 '06 #4

"Penn" <tr*************@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro 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
Jan 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Henrik S. Hansen | last post by:
I'm new to C++, and cannot figure out why this won't compile: std::map<std::string, int> tst; tst = 1; int main() { /*...*/ } It gives me: error: ISO C++ forbids declaration of `tst' with...
5
by: j0mbolar | last post by:
operator = (const char *string) { if(m_string) { free(m_string); m_string = 0; } if(string) { m_string = strdup(string); } }
4
by: Juhan Voolaid | last post by:
Hi I need help here. When i compile my program, i get this error: $ make g++ -c -Wall inf2_functions.cpp -o inf2_functions.o inf2_classes.h:6: error: ISO C++ forbids declaration of ‘vector’...
3
by: gamehack | last post by:
Hi all, Here's the error which I'm getting when trying to compile some code: boxmanager.h:16: error: ISO C++ forbids declaration of 'vector' with no type boxmanager.h:16: error: expected...
1
by: eric | last post by:
hello i'm trying to implement some functionality whereby an algorithm in a base template class relies on a function pointer supplied by a derived template class. the types are only specified by...
7
by: Florian Haag | last post by:
Hello, I'm trying to compile a programme which compiles fine under Linux; I'm trying it with MinGW G++ 3.4.2: Component.h: #ifndef COMPONENT_H_ #define COMPONENT_H_
8
by: aneuryzma | last post by:
Hello, I'm merging an OpenCV app with an Ogre3d app. I'm on a mac, I'm using xCode. When I add #include "openCVApp.h" I got the following error:
6
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing...
10
by: tvnaidu | last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.