| |

VerySource

 Forgot password?
 Register
Search
View: 888|Reply: 5

"Lifetime": the difference between "scope"

[Copy link]

3

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-10-9 11:00:01
| Show all posts |Read mode
"Lifetime": the difference between "scope"
Reply

Use magic Report

3

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-10-9 11:15:01
| Show all posts
and also
The difference between #include<iostream.h> and <iostream>? ? ? ? ? ? ? ? ? ? ? ? ? ?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-10-9 12:00:01
| Show all posts
The lifetime is only the existence time of an object
Generally speaking, scope is the scope of use of a symbol

void aaa()
{
   CMyObject* p=new CMyObject();
}

The scope of p is limited to this function, and the lifetime of the object pointed to by p is here until the end of the process (memory leak).
Reply

Use magic Report

0

Threads

20

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-10-9 19:15:01
| Show all posts
<iostream> is newer than <iostream.h>
To be specific, it involves namespace
such as:
# include<iostream.h>
void main()
{
cout<<"this is a test "<<endl;
}
or
# include<iostream>
using namespace std;
void main()
{
cout<<"this is a test"<<endl;
}
Did you notice? After <iostream.h>, there is no using namespace std; (using standard namespace)
And it must be used after <iostream>, otherwise cout will be marked as "undefined", (or to avoid it, std::cout can be used, and the name in every std namespace must be added std:: this is Very troublesome)
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 Invalid IP Address

Post time: 2020-10-9 20:15:01
| Show all posts
and also
The difference between #include<iostream.h> and <iostream>? ? ? ? ? ? ? ? ? ? ? ? ? ?
-------------------------------------------------- ---------------------
With .h means that the access to the C language library does not require a namespace
That is, there is no need to write using namespace std;
Without .h means that the access is to the C++ language library, which requires a namespace
Since C++ evolved from C, it has many features of C in order to be compatible with C
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-10-9 20:45:01
| Show all posts
and also
The difference between #include<iostream.h> and <iostream>? ? ? ? ? ? ? ? ? ? ? ? ? ?

-------------------------------

c is a function library, mainly there are some practical functions. When c++ is compatible with c, it also retains the standard library of c. That is
The c++ standard library also includes the c standard library. The newly added c++ are generally class libraries, such as io and string, which are class-centric
At the same time, C++ also includes a standard template library, which is a data structure written with templates.

The name of the c standard library in the c++ standard is changed like this:
xxxx.h ----> cxxxx
Such as:
stdio.h ----> cstdio


The newly-added c++ library is in line with the standard and outdated (libraries that existed before the standard was established for c++).
xxxx.h ---> xxxx
Such as:
iostream.h ---> iostream

In general, there is no end of .h. The c library needs to add the beginning of c.

All C++ standard libraries are included in the std namespace. The usage of the namespace is:
std::xxxx
Kind of similar to calling class members.
You can also import the entire namespace at once:
using namespace std;
xxxx
There is no need to use the prefix std:: to quote.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list