C++ Question Valid use of "cout"?

eveningsky339

Resident Orbiter Slave
Addon Developer
Donator
Joined
May 3, 2008
Messages
1,062
Reaction score
1
Points
0
Location
Western Maine
Hi everyone. I'm working on a simple calculator program for Orbiter that runs through the Magic Black Box. I feel as though I may be doing something wrong... Can cin and cout be used in a class definition, or must they be confined to the main() function?

For example...

Code:
//random.h

Class Random
{

RandomFunction(double a, double b);

}

Code:
//random.cpp

RandomFunction(double a, double b)
{

[COLOR=Blue]cout << "Enter a variable: \n";
cin >> a;[/COLOR]

}
The part in blue is what concerns me.
 
try:
Code:
std::cout << "blabla";

"std" might be needed if the class file doesn't declare to use the std namespace.
 
No, you can use cin and cout anywhere in an application that you like (as long as it's a command line app)
Okay, that's what I needed to know. :)

try:
Code:
std::cout << "blabla";
"std" might be needed if the class file doesn't declare to use the std namespace.
No worries, I declared std namespace. However, I'll keep this tidbit of info in mind for future reference. :tiphat:
 
Using it the way you are, though, I have to think that maybe your overall conceptual design isn't the best-thought-out.
 
Back
Top