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

Started by
182 comments, last by Dbproguy 15 years, 11 months ago
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!


You can pass parameters to a program though these. Common uses include specifying a file for out/input, or any other uses. argc is the number of arguments passed, while argv[] is the actual items. Most C++ compilers will accept that form, or the empty "int main()" for the main function.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Advertisement
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...

Quick tip for posting code here in the forums. You have two options [source] or [code]. Here's an example:
//visual help :)#include <stdafx.h>#include <iostream>int main () {    std::cout << "Look at me I work!" << std::endl;   std::cout << "std:: is the namespace qualifier for cout and endl." << std::endl;       return 0;}

error 6951: "No one invited me to play."


to see how i did that just hit "Edit" in the upper right corner above my post.

Beginner in Game Development?  Read here. And read here.

 

Thanks for your time Sr_Guapo :)

I think I understand the very basic idea of why these arguments exist and that is communicating with the outside world ( from the frame of a console application)I guess.

By the way, I strongly suggest anybody following this workshop to get familiar with using MSDN. If you are using Visual Studio, just highlight a word and press F1.
Have we sent the "Don't shoot, we're pathetic" transmission yet?
Quote:Original post by _EpcH_
Thanks for your time Sr_Guapo :)

I think I understand the very basic idea of why these arguments exist and that is communicating with the outside world ( from the frame of a console application)I guess.

By the way, I strongly suggest anybody following this workshop to get familiar with using MSDN. If you are using Visual Studio, just highlight a word and press F1.


No problem. MSDN is a great resource for windows development. It is great for finding tutorials, source code, and error messages. I recommend getting aquanted with it early on, it will help immensly.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
I'm just starting out here, so I may be missing something, but using MS Visual C++ 2005 EE and following the book word for word doesn't seem to have the intended result.

Please correct me if I'm wrong, or if there is a better way to do things. I needed to make the following changes to the steps in the book:

PAGE 19-20: Building the Hello World Project

2. Choose File, New - should read - File, New, Project

6. File, New - should read - File, New, File

7. C++ Source File - should read - C++ File (.cpp)
- also there is no option to name the file here

At this point, if you enter the code and Build as indicated in steps 9 and 10, you end up with nothing at all, because the file created seems to have no connection to the hello project.

There are two ways I found to get it working.

A) The less efficient way: Follow step 9, then manually save the Source1.cpp in the /hello/hello folder. Then in the Solution Explorer window, right-click on the hello project > Source Files folder and select Add Existing item, then choose the Source1.cpp that you just saved.

B) The better solution: Instead of following step 6, right-click on the hello project > Souce Files folder and select Add New Item and choose C++ File (.cpp) and name it hello. Then you can enter the code and follow the rest of the steps.

10. Build hello.exe - there is no .exe extension in the Build menu, it is simply Build hello or Build Solution.


Are my changes to the book's instruction correct for Visual C++ 2005 EE or am I missing something?


The only reason I figured this out is because I had already looked at Microsoft's Walkthrough: Using the Visual Studio IDE. Otherwise, I might have been completely lost.

http://msdn2.microsoft.com/en-us/library/ms235632.aspx


Quote:Original post by warsen
Are my changes to the book's instruction correct for Visual C++ 2005 EE or am I missing something?


I think the book may be dealing with Visual Studio 6.0, which is notably different. As for creating a source file: Once you have project, just click the "add new item" button and select C++ file (or whatever it is). You may have to search a bit to find the correct file type. Also, you solution B sounds perfectly fine as well.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Warsen,

Indeed you are correct. The instructions, as indicated on page 19, are for Visual C++ 6. Visual C++ 2005 is actually version 8. The earlier versions of C++, much like Dev-C++ didn't have as tight of integration with projects, and thus allowed you to add a file much more quickly, and without the need for a project at all.

The correct approach for .NET 2005 is:

Step 1: Create an empty project
  1. File->New->Project
  2. Select 'Win32' from Project types
  3. Select 'Win32 Console Application' from the Templates
  4. Type the name of the project and the location in the edit box near the bottom.
  5. Click OK
  6. When the dialog box appears click on "Application Settings" on the left
  7. Click "Empty Project" under Additional options.
  8. Click Finish
Step 2: Add files to your project
  1. Right click on your project in the Solution Explorer
  2. Add->New Item
  3. Click Code in the Categories List
  4. Select either C++ File or Header File as appropriate to the task
  5. Type the name of the file in the edit box near the bottom.
  6. Click Add
Building your executable
For solutions which only have a single project, Build Solution will do the same as "Build <projName>". Once you have solutions which are containers for multiple projects, you will need to choose either to build individual projects, or the whole solution.

I believe all of the tasks we will attempt in this workshop will require only a single project. As such, "Build Solution" should work just fine.

Cheers!

[Edited by - jwalsh on June 2, 2006 1:48:07 PM]
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
Sr_Guapo and jwalsh, thanks for the responses. It's good to know I'm headed in the right direction. Hopefully, it might also help out other absolute beginners like myself.

A BIG THANK YOU to all the tutors making this possible!
Quote:Original post by warsen
Sr_Guapo and jwalsh, thanks for the responses. It's good to know I'm headed in the right direction. Hopefully, it might also help out other absolute beginners like myself.

A BIG THANK YOU to all the tutors making this possible!

Warsen,

No problem. Thanks for bringing this to my attention. I have added instructions for VC++ .NET 2005 in the primary post. If any further people have difficulty, just direct them there. Now we've got workable instructions for most of the major compilers.

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

Setup First Code::Blocks Windows Console Project



1. Run Code::Blocks Program

"This image hosted by imageshack.us"

2. Click on File>New Project...

"This image hosted by imageshack.us"

3. Click on the "Console Application" then Click on "Create" button

"This image hosted by imageshack.us"

4. Save your project. I suggest you should create New Folder and name it what you want. And save it in that folder.

"This image hosted by imageshack.us"

5. Surprise! You complete the setup process now.

"This image hosted by imageshack.us"


------------------------------------------------
If you think it is useful, I will do the Visual C++.NET 2003 setup with the screenshot like it you
DinGY
Yesterday is history.Tomorrow is a mystery. Today is a gift"

This topic is closed to new replies.

Advertisement