Question:
Why Does This C++ Code Look Different?
Michael Jackson
2008-09-18 22:11:37 UTC
I saw a tutorial that outpurts a string by the following code:

Console::WriteLine(L"Hello World");


I have learned to output a string in C++, i should write:

cout<<"Hello World"; ... etc

So whats the difference?! Why the above differs than the one below!
Four answers:
Ahmed The Ninja
2008-09-18 22:44:33 UTC
That's C++/CLI - what connects C++ with .NET. It has its' own classes and functions for IO (like Console class). L before the quotes stands for Long Text, which is the way to represent string of wide characters (Unicode).



Unlike Xoax.Net said, learning C++/CLI is not bad thing at all. Microsoft is the dominant leader in computer industry, that's the truth, like it or not.



With that said, do learn standard console C++ first. Only after you're comfortable with the command-line world, you can consider doing some Windows GUI .NET stuff.



*Edit*: Funny thing, I too have a lot of experience with C++ (which extends beyond making 3-minute videos about opening Visual C++ and creating a project). Microsoft haven't announced any plans on dropping C++ support. I doubt they ever will, because C++ is still the most widely used programming language.
2008-09-19 05:40:27 UTC
That is probably Microsoft's C++. I would recommend against using it and stick to the standard C++ (cout):

http://xoax.net/comp/cpp/index.php



Microsoft came up with their own "extensions" to C++, which no one really uses. Anyone who wants to use Microsoft's stuff, is using C#. Native C++ is what people are using for high-performance programming, and Microsoft's managed C++ is not going to catch on.



Managed C++ will go the way of Microsoft's Java (J#). Has anybody used J# lately?



Microsoft makes a great C++ compiler, but their C++ extensions will fade away.
jplatt39
2008-09-19 05:47:12 UTC
In essence libraries and namespaces. Also, there is a writeln() function/method in standard c/c++. It's actually the equivalent of cout << messagestring << endl; or writeln('Hello World!'); in pascal.



Actually this is C# rather than C++ but the major differences are libraries. C# has a method for object Console called WriteLine(). C has a function in cstdio called writeln() which C++ inherited.
cld
2008-09-19 05:14:42 UTC
Console::WriteLine(L"Hello World");



to me that looks like C#.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...