C++ Bad Practice: using namespace std; #Shorts

preview_player
Показать описание
C++ Bad Practice: using namespace std; #Shorts

Learn why using namespace std; is bad for professional programming.

Master the fundamentals of C++ with Programiz's interactive and self-paced course. The tutorials include multiple topics ranging from basics of C++, flow control to advanced Object-oriented classes and objects all for FREE!

Moreover, you get the following features in the app:
- Curated bite-sized lessons.
- Tons of practical examples
- Practice and run code all within the app.
- Interactive quizzes to revise what you have learned.
- Track your progress

If you want to learn more hacks on programming, subscribe now. Also, do turn on your notifications so you will be notified whenever we post our videos.

PS. Follow us elsewhere for more amazing content:

#shorts #programiz #programming #beginnerprojects #programmingprojects #programmingjourney #learnprogramming #C++ #learntocode #namespace #programmingpractice
Рекомендации по теме
Комментарии
Автор

Download the newest Learn C++: Programiz app, now available on your Play Store and App Store!

programizstudios
Автор

Good advice, bad explaining of the reason why...

kgame
Автор

"What's the difference? I said it's bad." Nice explanation!

viniciusneves
Автор

"its not a good practice"

why ? because you said so ?

mariolis
Автор

Just use it since u are not really gonna use cpp in production maximum times. There are better alternatives for that.

Nutrino
Автор

#include <iostream>
using std::cout;

Int main() {
cout << "You can explicitly"
" declare what name"
" space object you will
" be using, namespace"
" is used to guard against"
" two different variable, "
"Functions, or objects "
"Having the same name"
" it's fairly safe you will "
"Not have another cout"
" object from another "
"Library";
return 0;
}

pnuema.
Автор

Instead you can use
using std::cout, std::cin, std::endl;

raffayshahzad
Автор

Real reason: if you have two namespaces with the same function the compiler gets confused which one you're using. Always good to clarify which namespace your code is coming from incase something with the same name exists inside another namespace too.

UnWorld
Автор

The reason is, in production there are so many namespaces in use, companies prefer using the whole namespace for clarity to where the expression belongs to.

uditnair
Автор

When giving advice, please include the reasons as well.

iqmal
Автор

#include <reasonwhyweshouldn'tdothat>

NoahM
Автор

We have to use std:: so many times and hence I prefer to just wrote using namespace std.

thepriestofvaranasi
Автор

Also bad practice to not end your program with a new line (\n or endl) so looks like you need to work on your stuff a bit more.

Dubov
Автор

you should of course avoid using namespace std when starting, first because when including another file for example
#include <array>
you will need write the std first like in this example:
std::array<int, 2> arr = {1, 2};
But when using the name space std the whole time, you'll just write it without std::, and you may not be able to know whether or not you should write std:: witch will make it very confusing .

tahaanass
Автор

I don’t remember ever using the std namespace… I don’t know why it’s such a popular thing

joevaghn
Автор

That's true, but imagine bringing down one piece by piece at a time wastes your time, the lines and you will have the peace of mind that you don't need to import everything from the standard library if the program is too huge and has many lines.

tharushasachindra
Автор

or just move using namespace std; into your main function

brennethd
Автор

its not problem if it is a small project

ГеннадийПолетаев-ум
Автор

because if use the name space as global you include the all functions of this class this memory wested

AI__VOICE
Автор

Maybe u will be importing third party library to ur project whic may use its own string or vector with their own functionalities which are different than standard, so how u differ third party lib vector from standard library vector is by using namespaces, third_party_lib::vector.... and u have std::vector, thats why u dont use using namespace std;

jovanrumenic
visit shbcf.ru