The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Undeclared identifier really starting to...

...make me mad

I am using VS2005 pro. I am trying to create a simple console app. I use cout to try to say "hello world"

:)

and it says that cout is an declared identifier...wtf is up with that?
Blake
Sunday, March 26, 2006
 
 
Under the current standard, cout lives in the std namespace.  You now want to write...

#include <iostream>

int main(void)
{
  std::cout << "Hello World" << std::endl;

  return 0;
}

Note also you should no longer write .h on the end of compiler provided include files.
Perl Solution
Sunday, March 26, 2006
 
 
Hmm.... why has it changed? What is std?

Also, the console app just pops up and doesnt stay....weird.
Blake
Sunday, March 26, 2006
 
 
There have been a fair number of changes to the C++ standard, and a number of additions over the years.  If you're looking to get up to speed on them I'd recommend "C++ Primer, 4th Edition" by Lippman, Lajoie and Moo.

When you run the "Hello World" program from Visual Studio a console window gets created, the program runs, and when the program is over the window closes.  If you want to see the results you can either put a request for input at the end of the program, or simply open up a command window of your own and run the program there.
Perl Solution
Sunday, March 26, 2006
 
 
>Hmm.... why has it changed? What is std?

It changed a while ago to support namespaces and start libraries. cout is now in the std namespace.

You can still use .h for your code, but C++ standard libraries need to not have .h appended.


> Also, the console app just pops up and
> doesnt stay....weird.

You probably need to ask for user input to block the window from going away after the program is done executing.
son of parnas
Sunday, March 26, 2006
 
 
you can just put
using namespace std;
at  the top of your files, and everything will behave as before.  Although I'm sure some purists are about to yell at me for saying that.
danielsn
Sunday, March 26, 2006
 
 
> Although I'm sure some purists are about to yell at me for saying that.

I won't yell, but's it bad practice because it's easy to get namespace conflicts.
son of parnas
Sunday, March 26, 2006
 
 
> Also, the console app just pops up and
> doesnt stay....weird.

When your program is finish running it will close down like any other program. So when done displaying "Hello World", which don't take long time, the app will close.

Start the app using CTRL+F5 instead of just F5 and it will stay open after main() is done or set a breakpoint there.

Consider also getting a beginner's book about VC2005, OK?
Patric J Send private email
Monday, March 27, 2006
 
 
Hi, I have a problem running hello world in Ruby.

I wrote:
print 'Hello world

But it sais "expected ' before endline". What did I do wrong?

I cannot find the answer to this question anywhere, and people keep telling me to use giigle or whatever it's called.

I'm absolutely clueless!

Please help me! I cannot possibly figure out what to do on my own.
Jeb
Monday, March 27, 2006
 
 
hi jeb

here is how to fix Your code: just add the thing the message says it epxected

so put "print 'Hello world' before endline" instead

i haven't tested this but i've been coding VB for nearly a year so yeah it should work
Blind leading the blind
Tuesday, March 28, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz