Learning C ++ C ++ acquaintance

Disclaimer :
            I am self-learning C ++, there is no basic computer, it is inevitable there will be mistakes in understanding the process of learning, irrelevant phenomenon, there may even be laughable. If you have C ++ Daniel to be able to sweep my blog, sincerely I hope that Daniel can give criticism and correction! Greatful! The learning process is divided into first met, entry, advanced three stages.
            
            Because there is no knowledge of C ++, set their own learning accuracy might be lost. Brothers hope more guidance. Thank you!



I am not a computer science graduate student. But after graduating from various coincidental, I embarked on this road IT. Work, more and more find their lack of knowledge. So give yourself a long time ago set the program to learn C ++. To be developed. DBA will not be developed, not a good DBA Haha, I have been convinced this sentence. In fact it, the very beginning, I said developing means is Oracle development, as here all the time, brought under direct apply, ha ha. Come, buddy child sister were children who have wanted to learn C ++ development, to start this road of no return it together with brother. Haha. . . . . I feel that they are still small before, now is a brother to speak ~, hey really old ah. . .

Before the start of it, saying the entry we need to see C ++ book. First elected to the inevitable is "The C ++ programming language", which is the parent of C ++ BS works, absolute authority, called知子莫若父thing. Haha. The second book, after scouring the sands of time, after the critical masses have sharp eyes, ultimately leave such a: good book "C ++ Primer", an absolute classic entry. I am currently learning C ++ is to learn to see through this book combines video, of course, I'm not a celebrity, he had no authority. From which book to start learning completely depends on your own if you feel any better, but also welcome to exchange with me. Let me also gives an eye to a quick Kazakhstan.
              
So get started!

First of all, first met C ++, directly to some theories it? What is the function? What is a namespace? What is a pointer? I do not think so, I think the combination of theory + examples of understanding, the most acceptable. If one up straight from the heart, talking about these theories, guess I never finish went dead sleep ~

Come on, we directly started.

First, the most simple C ++ program

to uncover the C ++ veil of mystery, let a simple C ++ program, but also to learn any one development language, straight to the point to write something: Hello world!

Let's look at C ++ source code:

#include <iostream>
intmain()
{
std::cout<<"Hello world!"<<std::endl;
}

 

I look at this code is compiled, what will be executed. But how to compile it?
We need to know C ++ source code is the code used by people, not the machine code that can be directly used. You asked me directly using machine code is valid? Oh, well think back, it was found so far away things ah. . . It is "10" two figures. . . Hey, that is, the binary. So here not to discuss the binary complex stuff ha
then the code how do we put our people to use converted into machine code that can identify it? G ++ debut ~ haha.
g ++ is a C ++ compiler tool. If you learn C language, then you must be familiar with the GCC, they are the compiler, you can convert people can read the code into machine code that can read and understand. Usage is the same.
The most common method is to use g ++ 'source code files' -o 'output file'
If the above using only g ++ 'source code files' is not the problem, it will generate a default file: a.out

compiler:

halberd:/home/C++ # g++ ./hello.cpp       
linux-emf1:/home/C++ # g++ ./hello.cpp -o hello
halberd:/home/C++ # ls -la
-rw-r--r-- 1 root root 1782257 Jun 11 16:49 C++ Primer.4th.chm
-rw-r--r-- 1 root root     242 Jun 22 03:14 test.cpp
-rw-r--r-- 1 root root   13304 Jun 23 07:53 C++学习笔记
-rw-r--r-- 1 root root      93 Jun 23 21:23 hello.cpp
-rwxr-xr-x 1 root root   13154 Jun 23 21:23 a.out 
-rwxr-xr-x 1 root root   13154 Jun 23 21:24 hello   

 

                     

  • Here we note that ah, C ++ compiler is G ++, and C compiler is GCC, make no mistake, otherwise you will find that the code written obviously right, but the compiler is being given

carried out:

halberd:/home/C++ # ./a.out
Hello world!
linux-emf1:/home/C++ # ./hello
Hello world!
linux-emf1:/home/C++ # 

 



Normal execution, ha ha. The simplest explanation of this C ++ source code is still correct. Amazing ~

Hey, I whim, want to see a.out which in the end is what things, why go through the g ++ compiler will generate such a document?

linux-emf1:/home/C++ # strings a.out
/lib64/ld-linux-x86-64.so.2
libstdc++.so.6
__gmon_start__
_Jv_RegisterClasses
_ITM_deregisterTMCloneTable
_ITM_registerTMCloneTable
_ZNSt8ios_base4InitD1Ev
_ZSt4cout
_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
_ZNSolsEPFRSoS_E
_ZNSt8ios_base4InitC1Ev
libm.so.6
libgcc_s.so.1
libc.so.6
__cxa_atexit
__libc_start_main
GLIBC_2.2.5
GLIBCXX_3.4
UH-h
UH-h
[]A\A]A^A_
Hello world!
;*3$"

 


XX, in addition to "Hello world!" The other all do not know. . . . I instantly gave up. . . . . .



Second, the basic structure consisting of a C ++ program

actually developed by learned people know, "hello wold" program to run properly, first of all the source code must contain the necessary assembly language code to run properly, or that the structure is intact. The "Hello world" in all languages are just the key point is called the output function of the language
then C ++ program source code to run properly, there must be what structures it?

#include <iostream> / * this line, is calling C ++ header files, include the meaning that is included, that is, run a C ++ program must contain at least one header file can run normally. As for what is the first document, the role of header files and so on, you think too much, you can not keep my mind slow, while we re-learning. * /
intmain () / * This line has a int, this is doing? First briefly about here, int is a built-in data types in C ++ - integer, careful ah, not shaping ~ we do not study followed by a stick ~ int main (), if you learn a programming language, even if only a shell, to see the back of the small main () {} there are the following should be aware that this is a function, right? , Hehe. About main function, is a necessary part of the C ++ runtime, every C ++ program must contain the main function. * /
{// Start function body
"! Hello world" std :: cout << << std :: endl; / * this line is the key to hello world, call the cout namespace, the \ "Hello world \!" Is output to the screen. No contact with C ++ and is not confused, Shajiao namespace ah? Haha I have a good sense of accomplishment, the back of the learning process will be described in detail. Here it is that under the namespace is like a toolbox, toolbox that you have the tools needed to work. cout is a tool, a tool output. * /
} // end of the function body

 

 

This is what the entire source code of the hello world.
So by the above description, you find a couple of C ++ source code necessary to compile the normal structure?
I found two, one is the header file references Include part, the other is the main function.

Third, thinking
to constitute a C ++ source code that you did not understand? Haha is not that simple, simple lines of code 5, the two parts will write a C ++ program.

Hey, I want to blow you look at the black heart, not happy too early, you really understand it? Let's think together ah few questions:
What role 1. #inlude is it? '<>' These two symbols is doing it? There is no other symbol can replace it? If so, the meaning of different symbols represent what difference does it? It was '<>' references and content together is what is it? How much do we know about it?
2. int C ++ is a language built-in functions - integer. C ++ built-in function that how many do? Commonly used, what does? Different built-in functions, what purposes?
3. std what is that? What role do? '::' two colons together is what does it mean? What is the role cout have it? '<<' number two less than they represent what does that mean?
I would also like to ask a few questions, I am afraid, because consequently do not really know. . . 555555. . . .
But never mind, a few days I'll know, you have a few days to answer me. Hey
all right, when to write something yourself, become familiar with the development of language, you must write something every day, otherwise they have forgotten. . . .

We do not write hello world, and we tokens of a I LOVE YOU, ha ha. Later, I learned to write windows programs can be written confession, then a small program, and then sent to their favorite girl. . . . It is not very Cock wire ah. . . Haha Fourth, review our learning of it through today, I have learned what things?

 

1. The simplest C ++ source part
2. How to compile C ++ source code for the operating system executable file (g ++)

Guess you like

Origin www.cnblogs.com/halberd-lee/p/11068681.html