编程知识 cdmana.com

The most simple and easy to understand C + + tutorial lesson 1

Lesson one

One , Why is there C++? And C++ And C The difference between

     as everyone knows ,Windows、Linux Use... Etc C Language development . But as computer performance improves , Hardware configuration is very different from decades ago , The scale of software is also expanding , A lot of software is bigger than 1G, for example PS、VS etc. , use C Language development of these software is very difficult ,C++ So it came into being .C++ seeing the name of a thing one thinks of its function ,C++ Is in the C Adding new functions on the basis is its “ Upgraded version ” It's like Win10 and Win7 The relationship between . It is embodied in :C++ Mainly in the C On this basis, the object-oriented and generic mechanisms are added , Enrich the library function , Improved development efficiency , Suitable for large and medium-sized software writing .

    But not in the early days “C++“ The name , It is called ” With class C“.1983 The name was changed to C++( among “++” It's taken from C In language “++” Operator )” Its positioning is obviously as C Language is an extension and supplement , here C++ Very rough , It only supports simple object-oriented programming and does not have its own compiler , Through a preprocessor ( Name is Cfront, But later on Because it's hard to support C++ Exception mechanism is discarded ) First the C++ Translated into C Code , Re pass C The compiler synthesizes the final program . But as the C++ popular , It adds a lot of functions , For example, function overloading 、 quote 、const Keywords and // Notes, symbols, etc . And in the years that followed C++ It has been developed rapidly .C++ Constantly updated , Class added protected members (protected) And private members (private) And allow multiple inheritance ; Can be very perfect support object-oriented programming and generic programming . But no new one has been born C++ compiler ( But then there was ), It's about the original C The compiler keeps expanding to support C++ New features, so we usually call it C/C++ compiler , Because it supports C and C++, in other words , You wrote it. C、C++ Code can be compiled with a compiler ( Now in general use Visual Studio To compile the C++ Program ), It's hard to say. C++ It's an independent language , Or right C An extension of .

Two , About C++ Learning from

From my learning experience , Yes C The basis of language C++ It won't be difficult ,C++ Support process oriented programming 、 Object oriented programming, etc , and C The language only supports process oriented programming . Just for process oriented programming ,C++ and C Almost the same, so have confidence in yourself .

in my opinion , Programming is about thinking ( Solutions to problems , Method ), Programming languages are second ( But you have to knock more code to make it perfect ), There are many languages to solve the same problem , Which is better or worse is just who is more efficient , There is no absolute difference between good and bad . And the computer field is changing very fast , No one knows what language will replace , It doesn't make much sense to be confined to the language itself .( But it doesn't mean that I think I can get things done in a hurry when I study )

Finally , Besides typing more code , I think the best way to learn is to set goals and then summarize them in the process of learning . After learning a new thing, compare it with the previous one to find out the difference , There's a lot to sum up , You'll find that languages are similar , The code is the same .

3、 ... and ,Visual Studio Installation

About VS I will not elaborate on the installation here ( You can use other compilers if you want to , After that, I'll use VS To compile the , I'm using VS2017), I recommend two very professional software solutions for official account “ Software Manager ”,“ Box tribe ” It's very comprehensive , Download from resources , The installation process is also very detailed , There's a lot of rogue software in it .

Four , Create a project file and write a simple C++ Program

1> Create project files

Start by opening VS, Click to create a new project , choice Visual C++ Empty project for , Fill in the name and click OK , At the bottom of the screen “ Creating project succeeded ” A hint of ;

Next, select add new item below the item bar , Choose .cpp file , Modify name , Finally, click Add , You can write the program .

 

2> Write a simple one C++ Program

every last C++ Programs contain one or more functions , And there must be one named main The operating system calls main To execute the program (main Functions are the only functions that are displayed and called by the operating system ),main Function executes its own statements and returns a value to the operating system . Here's a simple main function , It does not perform any function, just returns a value .

int main()

{

return 0;

}

The operating system passes through main Function to determine whether the program is successfully executed , return 0 Indicates that the program has been executed , The only statement in the example is return, It means that the statement is terminated ,( And pay attention return The semicolon after the statement , Never omit )

 

版权声明
本文为[NarutoZ]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225110749833Q.html

Scroll to Top