Brian's Bumblings

Sunday, January 01, 2006

myfirst.cpp

For the next few posts I will be looking at the difference between Listing 2.1 myfirst.cpp from C++ Primer Plus and a similar C# app.

Listing 2.1 myfirst.cpp
// myfirst.cpp--displays a message

#include <iostream>
int main()
{
   
using namespace std;
   cout <<    "Come up and C++ me some time.";
   cout << endl;
   cout << "You won't regret it!" << endl;
   return
0;
}


The closest C# app I could write looks like this.
Listing 2.1-C# myfirst.cs
// myfirst.cs--display a message

using System;
class
MyFirst
{
   static int Main()
   {
      Console.Write(
"Come up and C# me some time.");
      Console.Write(Environment.NewLine);
      Console.Write("You won't regret it!" + Environment.NewLine);
      return 0;
   }
}


The next few posts will look at the following elements of myfirst.cpp vs. myfirst.cs
  • The main() vs. Main() Function
  • Function Headers
  • C++ vs. C# Comments
  • #include vs. using
  • Namespaces
  • cout vs. Console.Write()
  • C++ vs. C# Coding Style

0 Comments:

Post a Comment

<< Home