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
-
5`Console::WriteLine` isn't C++. It's C++/CLI, which is more or less C++ running on .NET. – chris May 15 '13 at 05:37
-
By the way, `cout` is an `ostream` object for `stdout`. `cin` is an `istream` object for `stdin`. – chris May 15 '13 at 05:40
2 Answers
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 <<
& >>
.
-
Thanks everyone for your answers but what really confuses me is that Console::WriteLine and cout<< seem to DO the same thing and I found it very unlikely that all Console::WriteLine does is call cout<< otherwise they wouldn't have even bothered making it so can someone also help me with that? Thanks – Ehren Patel Jun 04 '13 at 02:01
-
1@EhrenPatel `Console::WriteLine` is part of the .NET library. The .NET Library is available for use from C#, VB# etc. Those languages do not have `cout`. – user93353 Jun 04 '13 at 03:04
-
Does C++ have any standard function that writes a line to the console, i.e. automatically puts an `endl` at the end of your input? – Kyle Delaney Apr 28 '18 at 22:32
-
1
-
@user93353 Thank you, I didn't know about that. But is there one that works for more than just strings? – Kyle Delaney Apr 30 '18 at 03:30
-
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.

- 486,780
- 108
- 951
- 1,012