Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

wilhil

im so dumb! need help with hello world c++ project!

This topic is 5213 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

edit - In this post, I am simply trying to get help learning all about c++. I ask questions and people help me! thanks to everyone who has so far. No need to read everything, if you have time, please go down to the last question from wilhil, and answer... Thanks everyone for your help. [edited by - wilhil on May 12, 2004 5:20:36 PM]

Share this post


Link to post
Share on other sites
Advertisement
Telling us what the actual problem is would help.....

what Error messages / Warnings are you getting?

Share this post


Link to post
Share on other sites
h:\my projects\console 2\console 2.cpp(8): error C2065: ''cout'' : undeclared identifier


sorry! i forgot!

Share this post


Link to post
Share on other sites
try

using namespace std;

after #include "stdafx.h"

that will you let you use all the std you''ve included without going

using std::cout
using std::cin

etc.. for each command you want to use.

Share this post


Link to post
Share on other sites
Firstly you''re not including the "using namespace std" directive and secondly you talked about how you created your console application and C++ file but not how you created and included your header file. Did you create your header file in your project?

Share this post


Link to post
Share on other sites
It created everything automatically, and I just changed the .cpp file to add what I wanted.

Share this post


Link to post
Share on other sites
ok

std:: before works fine

thanks, but please can you explain what it does, what it means e.t.c.

I am currently working from http://www.cpp-home.com/tutorial.php?21_1
but i guess it is out of date then.

does anyone else know a free online tutorial that explains from the very beggining?

Share this post


Link to post
Share on other sites
You are sending the constant character string "test" to the standard output stream (represented by std::cout in C++ iostream library).

If you know nothing about programming, I would recommend buying a beginner''s book on C/C++ and spending a lot of time in the first couple chapters.

Regards,
Jeff


[ CodeDread ]

Share this post


Link to post
Share on other sites
I have been programming in visual basic for years now. I want to move to c++, In the tutorial I found, it didnt have the std:: bit, so I didnt understand it.

thanks

Share this post


Link to post
Share on other sites
Namespaces were introduced to avoid name clashing in large projects. By encompassing functions/methods in a namespace it provides a way of distuinguishing between two methods which look the same to the compiler:

//everything after this is enclosed in namespace Foo
namespace Foo
{
void SomeFunc(int SomeParm);
}

void SomeFunc(int SomeParm);

Now if you was to call SomeFunc like this:
SomeFunc(2358975);

You would be calling the non-Foo namespace method because the namespace declaration acts as an extra scope barrier.

To get to data declared inside a namespace you have a few options: you can either place the namespace name followed by the scope-resoluition operator ( :: ) directly before the method name to say you want to call the method inside that namespace like so:
Foo::SomeFunc(33565);

This can be a bit of a pain so alternatively you can add using namespace Foo; at the top of the file and everything declared inside the Foo namespace will be brought into scope.

Regarding your question everything in the C++ standard library is placed in the "std" namespace so to get access to cout/cin etc you must either use std:: before the identifier names or add using namespace std; to stdafx.h as has already been mentioned.

EDIT: removed forum smilies

[edited by - Spudder on May 10, 2004 12:08:03 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!