Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Count Undeclared?!?

hello world declare

  • Please log in to reply
5 replies to this topic

#1 Saint

Saint

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 63 posts

Posted 29 September 2006 - 02:59 PM

I'm using g++ in Redhat linux and I have code like this:

#include <iostream>

int main()
{

cout << "Hello World!";
return 0;
}


but I get a count undeclared. Does iostream not have cout in it?
  • 0
Hi >> Saint

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 30 September 2006 - 10:27 PM

iostream does have cout in it lib, but you have to declare the namespace or whatever its called...try adding this below the header includes
using std::cout

  • 0

#3 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 01 October 2006 - 11:57 AM

I'm using g++ in Redhat linux and I have code like this:

#include <iostream>

int main()
{

cout << "Hello World!";
return 0;
}


but I get a count undeclared. Does iostream not have cout in it?


Your error is probably "cout undeclared". cout is located in the std namespace, so your coude needs to either be
#include <iostream>

int main()
{

std::cout << "Hello World!";
return 0;
}


or

#include <iostream>

using std::cout;
int main()
{

cout << "Hello World!";
return 0;
}


  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#4 dirkfirst

dirkfirst

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 351 posts

Posted 02 October 2006 - 01:44 PM

I'm fairly sure he meant cout
  • 0

#5 Saint

Saint

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 63 posts

Posted 03 October 2006 - 04:32 PM

Whoops! I meant cout. When did linux start using Namespaces? I thought this was a microsoft thing. What is a namespace exactly, just another name for a class, right?
  • 0
Hi >> Saint

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 05 October 2006 - 08:33 AM

Namespaces are a way to collect code from multiple files under an umbrella. For example, the standard library is in namespace std::. The advantage is that you are unlikely to accidentally use both the same namespace AND same variable/class name. But without namespaces you could easily use a somewhat obscure variable name and have a definition collision.

Namespaces are NOT part of linux, they are part of C++.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Also tagged with one or more of these keywords: hello world, declare

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download