escanive

Hi,

I'm 16 years old and I want to start programming in C++. I have decided to use Microsoft Visual C++ Express to compile with. My goal is to make my own 3D game, but I know there are many years before I can do that.

The first thing I want to do now is to create a simple Console program saying "Hello world". Like this one I found on Wikipedia:

#include <iostream>
#include <ostream>

int main()
{
   std::cout << "Hello, world!" << std::endl;
   return 0;
}

I have a couple of questions:

1) Does this code need to be adapted in order to compile correctly with Visual C++ Express, because when I tried to compile it with Bloodshed C++ and tried to launch it, it just opened and closed again.

2) The next thig I will do is to create a message box saying "Hello world" with a "Ok" button. I have heard about a GUI software toolkit called QT4 from Trolltech (se quote below).

Qt uses standard C++, but extends the language by providing an additional pre-processor that generates the C++ code which is necessary to implement Qt's extensions.

Source: Wikipedia

Does this mean that I can creat a GUI in Qt and compile the C++ code in Visual C++ Express



Re: Visual C++ Language Beginning C++

n0n4m3

Hi,
here's the answers to your questions:

1- The window you saw was probably a console window and since you only print a message in that window it closes right away. Try this program:

#include <iostream>
#include <ostream>
#include <conio.h>

int main()
{
std::cout << "Hello, world!" << std::endl;
while(!_kbhit());
return 0;
}


It should keep the console window opened till you press a key.


2- Yes, you can create a GUI in QT and compile it in Visual Studio C++ Express. You also have other alternatives: use the windows api or WxWindows that's also cross platform.






Re: Visual C++ Language Beginning C++

escanive

thanks alot for the help, n0n4m3



Re: Visual C++ Language Beginning C++

Simple Samples

I don't know what Bloodshed C++ is. I think it is outside the scope of this forum; if so, then you should ask in a forum for it. I will assume that you are using Bloodshed C++ in the Visual Studio IDE, although I realize that might not be true.

The VS IDE is a little confusing since it makes it easier to execute a program using the debugger than it does to execute without the debugger. It does that by providing a toolbar button to debug and by providing the F5 key to debug. To execute without the debugger, use Ctrl-F5 instead of F5. In addition to that, when a console program is executed using the debugger, the console window is closed immediately after execution. The console window however is not closed if the program is executed without the debugger. So in other words, if you execute your console program using Ctrl-F5 then you don't need the extra code to pause the program at the end.

Note that I had to type a long explanation of that. I hope it helps. Most people, when they answer this question, don't bother to explain all this and simply say that you must add code to pause at the end of the program.

As for saying "Hello world" or whatever with a "Ok" button, you can use Windows for that but Windows programming is outside the scope of this forum. There are many other forums where you can ask about that. The following however shows how easy it is to use the Windows MessageBox function.

Code Snippet

#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>


int main(int argc, char* argv[]) {
UINT uType = MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND;
MessageBox(NULL, "Hello", "Simple Application", uType);
return 0;
}






Re: Visual C++ Language Beginning C++

IB00

Hello escanive,

If you are only interested in learning C++ then you can ignore my message.

If you are interested in using Microsofts version of C++, that is C++/CLI, then I would strongly enourage you to stop and learn another Microsoft language such as C# or VB. Compared to the number of books on C# and VB, there is only a handful of books on C++/CLI. They are not complete and you will only have to invest in a lot of C# books in the end. Search for C++/CLI in any online book store and you will only get a handful of references. There is relatively little support for C++/CLI compared to that for C# and VB. You will also find the integrated development environment (IDE) works almost effortlessly with C# and VB but bogs down with C++/CLI. The C++/CLI debugger is slow and you will likely have to spend a lot of time trying to find a work around solution or which options have to be disabled in order to get adequate performance. I've spent many hours trying to track down bugs in my code only to find out the debugger was itself buggy. I have yet to get the debugger to display the contents of a generic list in the watch window (see http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=989028&SiteID=1) . There are nuisance bugs in the IDE for C++/CLI that make code navigation awkward and downright inconvenient (e.g. double clicking on a class function in the Class View more often then not puts you in the header (.h) file instead of the source code file (e.g. .cpp). There are bugs in a number of the wizards (e.g. the wizard used for adding a new class will not allow you to place the files associated with the new class in a directory of your choice) . I have found that VS works extemely well with C# but, in contrast, have encountered one problem after another while working with C++ (e.g. see http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1367331&SiteID=1). When I first received the release version of VS2005 in the fall of 2005, it crashed on a regular basis because of bugs in Intellisense - it took 2 patches from MS to correct the problem. If you are interested in learning C++/CLI then....dont'. Learn C# and/or VB instead and save yourself a great deal of frustration and delays.

Ian





Re: Visual C++ Language Beginning C++

Simple Samples

IB00 wrote:

If you are interested in using Microsofts version of C++, that is C++/CLI

C++/CLI is not Microsoft's version of C++.

IB00 wrote:

there is only a handful of books on C++/CLI

One reason is because CLI/CLR is a more recent version of .Net.

IB00 wrote:

If you are interested in learning C++/CLI then....dont'. Learn C# and/or VB instead and save yourself a great deal of frustration and delays.

The question did not ask about CLI/CLR.

C++ existed long before CLI/CLR did. It is entirely possible to develop 3D graphics programs and compilers and operating systems using C++ without any CLI/CLR.






Re: Visual C++ Language Beginning C++

IB00

Hello Sam,

1. What other companies are promoting C++/CLI Obviously I'm not aware of them.

2. C++/CLI is indeed new, hence the scarcity of books and a good reason why an young (possibly inexperienced programmer) would be better off learning another language that is well documented.

3. As stated in my first sentence, ignore my message....

4. I've been using C++ for quite a few years. I'm not certain why you made this point.

Ian





Re: Visual C++ Language Beginning C++

Simple Samples

IB00 wrote:
I'm not certain why you made this point.
The question did not ask about CLI/CLR.

Your comments are more appropriately placed elsewhere. If you disagree then please complain to Microsoft or a moderator. I am confident they will agree that the comments are more appropriately placed elsewhere.






Re: Visual C++ Language Beginning C++

IB00

Hello Sam,

The information I shared is valid and accurate. This person clearly does not know C++. Given MS is actively promoting .NET and managed code, it is very likely he will be directed towards C++/CLI. I believe the information I provided is very helpful, is not an abuse of this newsgroup and certainly not the rantings of an mad man. But enough said, we have better things to do. Thanks for your input and I wish you a good day.

Ciao,

Ian





Re: Visual C++ Language Beginning C++

Ellie Jensen

hi,

It is interesting..., both of you are warmhearted.





Re: Visual C++ Language Beginning C++

itchy-intermediate

i'm only a very intermediate developer, however, i use the bloodshed IDE quite a bit myself, and had the same problem you're describing, and i believe the resolution is in the code, not a compatability issue (unless you're referring to the .vcproj files in visual studio, but your not).

So i think this MAY be the solution you're looking for, which is a "PAUSE" which means your code should read as follows and indicated in red:

#include <iostream>
#include <ostream>

int main()
{
std::cout << "Hello, world!" << std::endl;

system("PAUSE");

return 0;
}