Console::WriteLine() vs. cout

34,987

Solution 1

You are using C++/CLI and not just C++. C++/CLI is a Microsoft extension which allows you to write .NET code on Windows and allows you to use the .NET Library(CLR - Common Language Runtime).

Console::WriteLine is a method from the .NET Library - http://msdn.microsoft.com/en-us/library/kxcchfk6.aspx

When you are create a Project in Visual C++, it allows you to either create a C++ Project or a C++/CLI (CLR) project. The CLR Projects types are the ones where you can use .NET stuff. If you create a Win32 project or one of the other types, it's just C++.

If you are not creating projects & just compiling from the command line, then the /clr option is the one to use for C++/CLI.

cout & cin are iostream objects. The corresponding classes have operators << & >> overloaded - hence you are able to do output with cout<< & input with cin>>.

This Q & A gives a better understanding of why the design used << & >>.

Solution 2

The difference is that std::cout is standard and is therefore available in any C++ compiler on any platform, whereas Console is a Microsoft-specific extension.

Share:
34,987
Admin
Author by

Admin

Updated on May 16, 2020

Comments

  • Admin
    Admin about 4 years

    I've just started trying to teach myself C++ (I've been a C# programmer for about a year now) and I can't understand for the life of me what the difference is between Console::WriteLine("Hello World") and cout<<"Hello World", on a side note I'm not even really sure what cout and cin even are so any help with that would also be appreciated