Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the programming skills of C++

Shulou Source: shulou.com Published: 2022-06-02 09:43:28 09月11日 Update

This article mainly explains "what are the programming skills of C++". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought slowly and deeply. Let's study and learn what C++ programming skills are.

1. Debug mark

Apply preprocessing # define to define one or more debug tags, and manage the debug part using # ifdef and # endif in the code. When the program is finally debugged, you only need to use the # undef tag, and the debug code will disappear. The commonly used debugging is marked as DEBUG, and the statement sequence:

# define DEBUG

# ifdef DEBUG

Debug code

# endif

two。 Debug markup during run

Turns the debug flag on and off while the program is running. This can be achieved by setting a debug bool tag. This is more convenient for programs run on the command line.

For example, the following code

# include < iostream > # include < string > using namespace std; bool debug= false; int main (int argc,char*argv []) {for (int iDebug I < argc;i++) if (string (Arg v [I]) = = "--debug=on") debug= true; bool go=true; while (go) {if (debug) {debugging Code} else {}}

3. Convert variables and expressions to strings

However, use the string operator to implement the conversion output definition

# define PR (x) cout < < # x "=" < < x < <'\ n'

4.C language assert ()

The macro in < assert >, when using assert, gives him an argument, that is, an expression that is read as true. The preprocessor generates code to test the assertion, and if the assertion is not true, it sends an error message telling what the assertion is and fails for a while, and the program terminates.

# include < assert > using namsapce std; int main () {int iTunes 100; assert (iTunes 100) / / Fails} after debugging, add # define NDEBUG in front of # include < assert > to eliminate the code generated by red} Thank you for reading, above is the content of "C++ programming skills". After the study of this article, I believe you have a deeper understanding of what C++ programming skills have, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Code markup skills programming skills caching programming programs learning running content characters strings expressions preprocessing information parameters variables commands multiple that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Redmi NVidia Huawei