C + + Hello World

Source: Internet
Author: User

First try the most basic Hello world!

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { System.Console.WriteLine ("Hello world!" ); System.Console.ReadLine (); } }}

The ReadLine function is because my console does not appear to press any key to exit, so manually fill a readline to see the results (prevent the console from flashing directly)

Then we tested the backgroundcolor and foregroundcolor about the color.

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { System.Console.BackgroundColor = Consolecolor.green; System.Console.ForegroundColor = consolecolor.darkred; System.Console.WriteLine ("Hello world!" ); System.Console.ReadLine (); } }}

Effect:

And then try another one. Implement output Hello world!

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { Class1 HelloWorld = new         

CLASS1:

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class Class1 {public void Hello () { Console.WriteLine ("Hello World from class1!" ); } }}

If you change the Hello function to a static type, you can call it without instantiating it.

As follows

Main

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { Class1.hello (); System.Console.ReadLine (); } }}

CLASS1:

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class Class1 {public static void Hello () {Console . WriteLine ("Hello World from class1!" ); } }}

Try using the console's parameters

Setting content:

Code:

Using system;using system.collections.generic;using system.linq;using system.text;using  System.threading.tasks;namespace consoleapplication2{class program {static void Main (string[] args) { System.Console.WriteLine (Args[0] + "" + args[1]); System.Console.ReadLine (); } }}

Run results

C + + Hello World

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.