Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can't use "cout" in seperate functions
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sheepo39




PostPosted: Fri Dec 11, 2009 5:15 pm   Post subject: Can't use "cout" in seperate functions

I'm a beginning C++ programmer, and I'm reading a book on it and I'm at the part with declaring functions. I understand the whole concept of it and all, but I don't understand why you can't use "cout" instead of "return" to output a value.

Like

float bodyTempC()
{
float temperature = 37.0 ;
return temperature ;
}

void bodyTempF()
{
float temperature = 98.6 ;
cout << temperature ;
}

instead of

float bodyTempC()
{
float temperature = 37.0 ;
return temperature ;
}

float bodyTempF()
{
float temperature = 98.6 ;
return temperature ;
}

Doing the first will return an error, and won't compile, why is this, I'm fairly confused.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Dec 11, 2009 5:19 pm   Post subject: RE:Can\'t use "cout" in seperate functions

Your compiler will tell you why it doesn't compile. Probably because there is no cout. Did you mean std::cout ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
HRI




PostPosted: Wed May 05, 2010 7:50 pm   Post subject: Re: Can't use "cout" in seperate functions

Be sure to put in '#include <iostream>' at the start of the file. Also, the way you're using it, 'using std::cout;' would be a logical statement after the first. That way, you need only type cout rather than std::cout.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: