🎉 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
Hi Guys

I got an error when trying to run the debug

http://falconuk.co.uk/c++/error.jpg

just in case some one else gets this heres how to solve it

1, right click on the your project in solutions explorer
2, goto properties
3, under the "linker" list you see "debugging"
4, in the right pane window click generate degugging info and choose YES/DEBUG
5, ok this and your good to go

hope this helps

Ninja
Advertisement
Hey guys! Haven't gotten started on the book yet, but one thing I notice is everyone's consequtive use of "std::endl". Is it possible to use "\n" for the same thing, only by including "<iostream>", or do I have to include "<iostream.h>" for this to work? I personally much prefer the use of "\n" instead of anything involving "endl" (and especially "std::endl"), because "\n" saves me time and space.

Thanks in advance!
_______________________Afr0Games
Quote: Original post by Ninja87
Hi Guys

I got an error when trying to run the debug

http://falconuk.co.uk/c++/error.jpg

just in case some one else gets this heres how to solve it

1, right click on the your project in solutions explorer
2, goto properties
3, under the "linker" list you see "debugging"
4, in the right pane window click generate degugging info and choose YES/DEBUG
5, ok this and your good to go

hope this helps

Ninja

Yes, this is probably due to selecting "Empty Project" as the project type.

To jwalsh: I suggest you change the instructions for a new project to use "Win32 Console Application" instead. [edit] And select "Empty Project" in "Application Settings" in the dialog box that pops up.


jfl.

[Edited by - jflanglois on June 2, 2006 6:46:41 AM]
Quote: Original post by Afr0m@n
Hey guys! Haven't gotten started on the book yet, but one thing I notice is everyone's consequtive use of "std::endl". Is it possible to use "\n" for the same thing, only by including "<iostream>", or do I have to include "<iostream.h>" for this to work? I personally much prefer the use of "\n" instead of anything involving "endl" (and especially "std::endl"), because "\n" saves me time and space.

Thanks in advance!


You are free to use \n in place of endl:
cout<<"Hello, world!\n";

You still have to include iostream (never iostream.h) to get access to cout, though.
------------------------------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.
Quote: Original post by Afr0m@n
Hey guys! Haven't gotten started on the book yet, but one thing I notice is everyone's consequtive use of "std::endl". Is it possible to use "\n" for the same thing, only by including "<iostream>", or do I have to include "<iostream.h>" for this to work? I personally much prefer the use of "\n" instead of anything involving "endl" (and especially "std::endl"), because "\n" saves me time and space.

Thanks in advance!


You can use '\n', but there is a reason for using std::endl. The reason is that std::endl will flush the stream if it is said to be buffered. A buffered stream is one that does not send your data directly to its destination. "Flushing" the stream is the act of actually sending the data to its destination. When you get to file streams, this will be important.

As for std::cout, I'm not entirely sure if it is required to be a buffered stream (it isn't as far as I can tell on WinXP/VC2005), but here's a basic rule of thumb: if you want to make sure your data gets to where its supposed to go when adding a new line, use std::endl. Otherwise, you can use '\n'.


jfl.
Quote: Original post by _EpcH_
*** Source Snippet Removed ***

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!

Although Sr_Guapo has got it right, I must add that _tmain and _TCHAR are not standard. They exist to accomodate wide-character strings (wchar_t[]) as well as normal (MBCS) strings (char[]) and should not be used if writing cross-platform code.

You will find that the standard notation is like so:
int main( int argc, char *argv[] )

[edit] I should also mention usage of underscores (_) in identifiers.
The standard says:
Quote: From here
Each name that contains a double underscore ("__") or begins with an underscore followed by an uppercase letter (lex.key) is reserved to the implementation for any use.
Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace. [as well as in the std namespace]
This means that: (1) to be on the safe side, do not use leading underscores ([opinion] followed by a lowercase letter or not [/opinion]) or double underscores in your identifiers (e.g. int _myint;) (2) do not expect an identifier with a leading underscore or double underscores to have the same behavior on different platforms (case in point: _tmain and _TCHAR)


jfl.

[Edited by - jflanglois on June 2, 2006 9:48:50 AM]
The new Cpp Workshop forum is waiting for this thread! Can one of you, cool moderators1, move the C++ WS threads into the newly created forum?



1: yeah, I know, I forgot to tell you that you are teh best!§!!!11one
hi all,

I've been using Open Watcom 1.5, if I'm behind I'm sorry took me a little while to figure it out but http://gravesworld.org/c++1.html :) havn't figured out how to debug :( tho I'll figured it out.

As to this:
#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << std::endl;
std::cout << x + y << " " << x * y;
std::cout << std::endl;
return 0;
}

Hmm.. my guess is that random numbers?
Am I doing this right?
http://cma.zdnet.com/book/c++/index.htm

I started on this a long time ago. I got up to about day 6 and stopped for some unknown reason. Maybe I'll try again. :o
Quote: Original post by Yu Une
hi all,

I've been using Open Watcom 1.5, if I'm behind I'm sorry took me a little while to figure it out but http://gravesworld.org/c++1.html :) havn't figured out how to debug :( tho I'll figured it out.

As to this:
#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << std::endl;
std::cout << x + y << " " << x * y;
std::cout << std::endl;
return 0;
}

Hmm.. my guess is that random numbers?

Why do you think that is so?

Also, I don't think you should be using Open Watcom. By their own admission, their STL implementation is incomplete, as well as having what they call an "old-style" (read: non-standard) IOStreams implementation. This will undoubtedly become a problem later in the book.

This topic is closed to new replies.

Advertisement