开发者

Visual studio for c++?

I have installed visual studio express 2010 c++. However when trying to follow a beginners book and make the hello world program, visual studio opens up a project with this in it:

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}

The thing is, this looks nothing like the c++ in t开发者_如何学Gohe book i have just started reading (C++ Without Fear). In fact, if i type 'cout',even after entering using namespace std, cout is not found.

This is the books example:

                      #include "stdafx.h" 
                      #include <iostream> 
                      using namespace std; 

                      int main() { 
                              cout << "Never fear, C++ is here!"; 
                               return 0; 
                       } 

Am i missing something here?


Create Windows (or Win32, don't remember exactly) C++ Console Application project, don't select C++/CLI project type.

C++/CLI is very special language, which is used only for interoperability between managed and unmanaged code. It is better to forget about C+++/CLI at this stage...


As Alex said start with C++ Win32 console project, but select empty project so that the IDE don't fill things out automatically! Go to Source Files in your Solution Explorer, right click on it and add new item and choose C++ file (call it main.cpp for example).

At that point you should be ready to go.

Try this sample code that I prepared for you...

#include <iostream>

using namespace std;

int main(char *argv[], int argc) {
    cout << "Hello World!" << endl;

    return 0;
}

It should print out Hello World! in the console.


You want to start with a Visual C++ Win32 Console Application.

If you want to create your own files completely (i.e. no stub file with a main defined), you can check "Empty Project" in the options of the Win32 Application Wizard.


This is not C++. This is so called "managed" C++. Basically, a totally different language by Microsoft that is compatible with their .NET platform. For example, you can mix C# code and managed C++ code in single binary. This technology is very Microsoft specific and is not portable to any other compiler/OS (even Mono, which is C# for Linux, doesn't have it). See Managed Extensions for C++ for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜