MinGW to run C + + in a Windows environment with a command prompt

Source: Internet
Author: User

Http://jingyan.baidu.com/article/4853e1e5787d6b1909f726f8.html

  1. Configure the MINGW environment in your computer.

    See my other share experience--MINGW configuration in a Windows environment:

    Http://jingyan.baidu.com/article/6b97984da0bd8a1ca2b0bf90.html

  2. 2

    Open a command-line prompt.

    See my other sharing experience--windows how to open a command line prompt in the environment:

    Http://jingyan.baidu.com/article/0320e2c1cf260c1b86507b4d.html

  3. 3

    Switch the path to the directory where C + + source code resides.

  4. 4

    View the C language source code.

    The source code is as follows:

    #include <stdio.h>

    int main ()

    {

    printf ("Hello world!\n");

    return 0;

    }

  5. 5

    The source code must finally have a blank line in the previous step, or the warning will be reported at compile time. This is because the compiler requires that the file end with a carriage return as the end of the file. Because the end of the line is connected to the next line, if the last line of a file (the right brace of the main function) has a/at the end of the line, then the first line of the next source file that immediately follows it is also connected, and if a file ends with a blank line, it avoids the occurrence.

  6. 6

    Compile the C language source code.

    Command format: GCC xxx.c-o xxx.exe

    Note: The above command can also add parameter options, for example:

    Gcc-g-wall Xxx.c-o Xxx.exe

  7. 7

    Run the C program.

    Command format: Xxx.exe (or remove the suffix name, directly using XXX)

    END
Method 2:c++
    1. Compile C + + source code.

      Command format: g++ xxx.c-o Xxx.exe

      Note: The above command can also add parameter options, for example:

      g++-g-wall Xxx.c-o Xxx.exe

    2. Run a C + + program.

      Command format: Xxx.exe (or remove the suffix name, directly using XXX)

    3. 3

      If the case is shown, refer to step 5th in Method 1 and add a blank line at the end of the source code.

MinGW to run C + + in a Windows environment with a command prompt

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.