🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ Workshop - Getting Started with C++ (Ch. 1 & 2)

Started by
182 comments, last by Dbproguy 16 years, 1 month ago
Quote: Original post by Palejo
Wow. Thank you for the fast responses and information:)

My pgm, however:

// Exercise1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

int main()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << x + y << " " << x * y;
std::cout << end;
return 0;
}

Still gets me:

error C2065: 'endl' : undeclared identifier
error C2065: 'end' : undeclared identifier

I've been staring at the code for a while now, making sure there are no typos...



Much like 'cout', endl is part of the Standard Namespace...hence:

std::endl;

...is the correct usage.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Advertisement
endl is part of the std namespace also, thus: std::endl.

[edit] - I'm so slow Duh!!
Quote: Original post by Palejo
Wow. Thank you for the fast responses and information:)

My pgm, however:

// Exercise1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

int main()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << x + y << " " << x * y;
std::cout << end;
return 0;
}

Still gets me:

error C2065: 'endl' : undeclared identifier
error C2065: 'end' : undeclared identifier

I've been staring at the code for a while now, making sure there are no typos...


Either change both of those (endl and end) to "std::endl", or add a line before int main saying "using namespace std". The compiler cannot find either of those commands since they are inside of the "std" namespace.

Edit: The code in the book is WRONG for chapter 1, exercise 1. Read the last few responses to find the correct code!
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
I'll add that to the top of the thread so people will know...
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Quote: Original post by Palejo
error C2065: 'end1' : undeclared identifier
error C2065: 'end' : undeclared identifier


Since those are our first errors, I would like to point out that getting acquainted to compiler error messages, their meaning and their probable cause is fundamental. Compiler writers go out of their way to provide meaningful error messages, so do pay attention to them, even if they're long, even if they contain unreadable alphabet soups (linker errors and template errors are particularly guilty of that), even if you aren't familiar with the terminology.

Additionally, if you're using Visual Studio, note that there is a help page for each error message, accessible via their error code (here, C2065). If you have never seen an error, or are not sure what it means, do read the error page.

"undeclared identifier" is your compiler telling you "I have no idea what you are talking about, I've never seen it before". It often indicates a typo or, like here, that you are telling the compiler to look in the wrong place. It may also mean that you have simply forgotten to provide the declaration, either by #includeing the appropriate header, or by writing the declaration yourself.

Finally, and I'm getting ahead a bit, know that there is a difference between a declaration (hence 'undeclared') and a definition. Pay close attention to what your compiler is telling you.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
hi Guys

have had all kinds of problems with vs 2005 express
mainly cant find file specified when trying to debug or run the file
so to get a move a on i d/loaded the dev-C++ and so far so good
but would ideally like to use the VS any ideas on whats happening here even tried with a clean install and got same message
Quote: Original post by Ninja87
hi Guys

have had all kinds of problems with vs 2005 express
mainly cant find file specified when trying to debug or run the file
so to get a move a on i d/loaded the dev-C++ and so far so good
but would ideally like to use the VS any ideas on whats happening here even tried with a clean install and got same message


Can you be more specific? What file can it not find? What error messages are you getting and when?

In theory, for VS EE, all you need to do is install and creat a new project. Have you changed any compiler settings? How are you creating the project?
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Quote: Original post by Ninja87
have had all kinds of problems with vs 2005 express
mainly cant find file specified when trying to debug or run the file


What error messages are you getting specifically, and what files cannot be found? Did you edit any of the pre-set directories for VS to search for files?

EDIT: Beaten to it...
------------------------------Support the Blue Skies in Games Campaign!A blog... of sorts.As a general rule, if you don't have a general rule in your signature, you aren't as awesome as someone who does. General rules roxor teh big one one ones.
heya

it was saying cannot find C:\Documents and Settings\simon\My Documents\Visual Studio 2005\Projects\hello\Debug\hello.exe

i managed to track the cause down though it was due to the .cpp file not being in the source folder in solutions explorer :( my bad there but hey all part of the fun :D

thanks for the quick replies
  // Hello World.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>int _tmain(int argc, _TCHAR* argv[]){	std::cout << "Hello World! \n";	return 0;}


First of all I am using Visual Studio Standard Version (Just received it yesterday :) ). I created a standard Win32 Console Project (didn’t select the empty project option), and it comes with the main function as seen above.

My question is, What are the int argc and _TCHAR* argv[] parameters for ? Why do we need them?

Thanks,
Cheers!
Have we sent the "Don't shoot, we're pathetic" transmission yet?

This topic is closed to new replies.

Advertisement