Advertisement

Visual C++

Started by March 16, 2002 03:51 PM
39 comments, last by sanguineraven 22 years, 7 months ago
quote: Original post by kvh
Make sure you create ''an empty project'', not ''a simple application'' or ''a hello world application''. Create a cpp file yourself afterwards.

Why?

What I hate most about the For Beginners forum is that the more experienced programmers don''t hang out here much, so beginners answer beginner questions. Wrongly, of course. kvh, I suggest you go read your MSVC manual. You can modify any workspace to build any sort of project. You can have multiple projects in a workspace (useful for developing libraries and test applications). You can add pre-compiled headers at any stage. And of course you can modify the source of one project type to whatever type you desire.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
Of course you can, I gave a simple straightforward solution exactly because this is a beginners forum.

I've been using VC++ for years and I make MFC apps for a living, I may not be an expert, but I think I can safely say that I passed the beginner stage.

The least you could do was to give him a better solution, instead of just bashing my (correct) post and adding nothing.

[edited by - kvh on March 18, 2002 11:42:20 AM]
Advertisement
My apologies. I subscribe to the school of thought (well, if there is no such school then I'm the founder ) that says introductory explanations should be as complete as possible without overwhelming the student. So I shall now provide a complete yet simple answer:

MSVC deals with the notion of Workspaces. A workspace hosts one or more Projects, which define a target platform, a type, and files included in the project. Within the workspace, browse information is made available that allows you to see the members of structures and parameters of functions when you declare/access them - IntelliSense. Unfortunately, IntelliSense is buggy as hell and craps out randomly, and also only browses files that are part of the project (added to the project), as opposed to simply being included.

The two most common project types in game programming are Win32 Console Application and Win32 Application. The first defines a project with entry point main and automatically allocates a console for the process, while the second has the entry point WinMain and doesn't pre-allocate any windows. That's the only significant difference between them, though others will misinform you otherwise.

Include files
C++ has been standardized (November 97, though it's called C++98), and the new standard defines all entities that are a part of the Standard C++ Library. This is basically the Standard Template Library and IOStreams. All entities in the Standard C++ Library are part of the std namespace, and therefore must be imported to be used. Personally, I avoid namespace pollution like the plague, so you will often see a bunch of using statements in my code as I import individual entities.

Standard C++ Library header files have no .h extension.
#include <iostream>#include <string>using std::cin;using std::cout;using std::endl;using std::getline;using std::string;int main(){  string str;  cout << "Enter a single-word string (may contain numbers): ";  cin >> str;  cout << "You entered \"" << str        << "\".\nNow enter any arbitrary string, including whitespace and punctuation: "<< endl;  getline(cin, str);  cout << "You entered the following string:\n" << str << endl;  return 0;}  


[Edit: Inserted the word "significant" somewhere in there...]

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

[edited by - Oluseyi on March 18, 2002 11:48:41 AM]
This Message is for the ORIGINAL POSTER! (if your still around!)

The problem you are having is that when you create a "Hello World" frame work with MSVC is it does not initially support cin and cout. Notice the "printf("Hello World);" , Instead of cout? Create an EMPTY win32 console app. Now give it a Whirl.

make a new cpp file in the Source Folder, and paste the following inside :

#include <iostream>
using namespace std;
int main(int)
{
cout << "Hello World";
return 0;
}

// This compiled just fine on my machine.
// REMEMBER!!! EMPTY PROJECT!!!
// Hope This Helps.
quote:
I subscribe to the school of thought (well, if there is no such school then I'm the founder ) that says introductory explanations should be as complete as possible without overwhelming the student.


Ok, I'll elaborate a bit.

The 'Win32 console application' wizard lets you choose between several different types of projects:

- an empty project
- a simple application
- a hello world application

The wizard not only generates code, but it also modifies the project's settings. The last two projects are set up to use precompiled headers, the first one isn't.

Now, precompiled headers in Visual C++ require some special attention, most importantly: all sourcefiles that use the precompiled header need to include it as the first statement in that file (everything before the include is simply ignored). The precompiled header is usually called StdAfx.h in VC++.

What I think you did was create a hello world application, delete the code that was in there, and drop in your own code. Of course, your project is still set up to use the precompiled header, but the '#include "StdAfx.h"' isn't there anymore, so it fails to compile.

So what you can do about it is either create an empty project, or like Oluseyi said, modify the project settings yourself. Here's some good info on doing that.


[edited by - kvh on March 18, 2002 1:35:12 PM]
yeah, that worked (finally) using an empty project and then adding it. another point, in many of hte tutorials i read (www.gametutorials.com) in their VC++ they used void main() but then in dev c++ they used int main(), whats the reason?

What about me? What about Raven?
Advertisement
void main() is illegal. The C++ Standard mandates that main() will always return int. Always! Microsoft, however, allow you to code void as the return type. main() is also special in the respect that you don''t need to code an explicit return statement. If you omit the return, then the compiler inserts a "return 0" for you. Microsoft, in their infinite wisdom, have decided to have their compiler output a "friendly" reminder if you don''t code the return statement. Ignore it.
As an OpenGL programmer, I actually prefer stdio.h over iostream/iostream.h :D

billy
What''s file i/o got to do with OpenGL? If you''d have said you are a C programmer, I might understand.
OMFG SabreMan!
Have you realized this is a BEGINNER FORUM yet? Why do you insist of bringing up illeged industry standards to people who are learning how to program? Is your ego so low that you need to bash on new(er) dev ppl about freaking standards? And who''s standards are you reffering to? You speak about these all holy Standards like there''s just 1 set of them. You stick to the rules way too much on this one. I am beginning to think you were potty trained way to young.
-nAZ

This topic is closed to new replies.

Advertisement