C + + Environment configuration in Sublime text 3 and command line Run window creation

Source: Internet
Author: User
Tags sublime text

This article is mainly to paste some questions about sublime text 3 C and C + + compilation Environment

We know that the current compiler is G++,GCC, however, when we use the sublime text to write C + + programs, we can only run in the building system of the default C + + Single file in sublime. However, it is not possible for users to enter them themselves, such as scanf statements, CIN statements.

So let's share my own methods for C++/C compiling environment settings and creating the type of cmd run window that we're used to.

First we know that gcc/g++ in our computer's cmd can compile our source program:

The specific format is:

GCC source file name-o executable file name//C language

GCC Test.c-o Test

g++ source file name-o executable filename//c++ language

g++ Test.c-o Test

So we can also building new system in sublime to create our C + + compilation system.

Of course, before this need to make sure that your computer has installed MinGW, this problem to solve itself. Bo Master himself is the previous installation of the dev C + + MinGW path set to the environment variable, the effect is the same drop.

1) C Language:
Sublime text under
I. Tool–>build system–> NEW Building System
Ii. Delete the default lines in the Open interface
III. Copy the following code paste Save as MyC.sublime.build

{"
    Working_dir": "$file _path",
    "cmd": "Gcc-wall \" $file _name\ "-o \" $file _base_name\ "",
    "File_regex": "^ (.. [^:]*):([0-9]+]:? ([0-9]+)?:? (. *) $ ",
    " selector ":" source.c ",

    " variants ": 
    [
        {   
        " name ":" Run ",
            " Shell_cmd ":" Gcc-wall \ "$ File\ "-o \" $file _base_name\ "&& start cmd/c \" "${file_path}/${file_base_name}\" & Pause\ ""
        }
    ]< c11/>}

It's OK.

2 the same C + + language
Sublime text under
I. Tool–>build system–> NEW Building System
Ii. Delete the default lines in the Open interface
III. Copy the following code paste Save as Myc++.sublime.build

{"
    encoding": "Utf-8", "
    Working_dir": "$file _path",
    "Shell_cmd": "g++-wall-std=c++11 \" $file _name\ "-o \ "$file _base_name\" ","
    File_regex ":" ^ (.. [^:]*):([0-9]+]:? ([0-9]+)?:? (. *) $ ",
    " selector ":" source.c++ ",

    " variants ": 
    [
        {   
        " name ":" Run ",
            " Shell_cmd ":" g++-wall- Std=c++11  \ "$file \"-o \ "$file _base_name\" && start cmd/c \ "${file_path}/${file_base_name}\" & Pause\ ""
        }
    ]
}

In the two configuration files above,
"Encoding" represents the character set
"Working_dir" represents the source program path
"Shell_cmd" on behalf of our compiler compiled instruction format, is our g++ source file-o specified file
"Selector" is the language of our source program.
Here the-std=c++11 is specified with the C++11 syntax compiled, of course, can not add

After saving, take C + + as an example, first we select our Myc++.sublime.build in the tool–> build system

Write a simple program:

Ctrl+shift+b Select myc++ to compile, then select myc++ Run

At this time automatically pull up our cmd run box, complete.

Next when we enter Chinese in the source program is again run time will find that there are garbled

The reason is that our cmd character set is different from the character set of our source program, the source program is Utf-8
Open our cmd input chcp command to view the current character set, default is 936

So we can modify it in our configuration file so that it supports GBK format
The specific operation is in the configuration file "Shell_cmd" to join the -FEXEC-CHARSET=GBK statement

{"
    encoding": "Utf-8", "
    Working_dir": "$file _path",
    "Shell_cmd": "g++-wall-std=c++11-fexec-charset= GBK \ "$file _name\"-o \ "$file _base_name\" ",
    " File_regex ":" ^ (.. [^:]*):([0-9]+]:? ([0-9]+)?:? (. *) $ ",
    " selector ":" source.c++ ",

    " variants ": 
    [
        {   
        " name ":" Run ",
            " Shell_cmd ":" g++-wall- STD=C++11-FEXEC-CHARSET=GBK \ "$file \"-o \ "$file _base_name\" && start cmd/c \ "\" ${file_path}/${file_base_name }\ "& Pause\" "
        }
    ]
}

Save

At this time in the compilation of our Code to run:

Perfect here we can use sublime this sexy editor to write our C + + code, of course the C language is the same.

Related Article

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.