http://stackoverflow.com/questions/1452721...ed-bad-practice
CODE
#include <iostream>
using namespace std;
int main()
{
return 0;
}
This post has been edited by Azusa_San: Jul 22 2015, 07:47 PM
C++ C++ using namespace std, a bad practice?
|
Jul 22 2015, 07:47 PM, updated 9y ago
Show posts by this member only | Post
#1
|
Junior Member
267 posts Joined: Mar 2015 |
for c++, is "using namespace std" in global consider bad practice? then why university lecturer still teach in this way?
http://stackoverflow.com/questions/1452721...ed-bad-practice CODE #include <iostream> using namespace std; int main() { return 0; } This post has been edited by Azusa_San: Jul 22 2015, 07:47 PM |
|
|
|
Jul 22 2015, 08:38 PM
Show posts by this member only | Post
#2
|
Junior Member
30 posts Joined: Oct 2014 |
Depend on how you use it
|
|
Jul 23 2015, 01:59 AM
Show posts by this member only | Post
#3
|
VIP
6,008 posts Joined: Jan 2003 |
I don't know why your lecturer taught it that way, but if you feel that it's wrong why don't you bring it up to him? Go build up your assertive communication skills
|
|
Jul 23 2015, 02:03 AM
Show posts by this member only | Post
#4
|
Senior Member
1,626 posts Joined: Apr 2013 |
i currently studying degree in software engineering, 2nd year student, mmu.
my foundation and 1st year degree, all lecturer teaching "using namespace std;" for c++ lol.... is it really a bad practice? lol... maybe becoz lecturer knowledge outdated xD? who know |
|
Jul 23 2015, 09:32 AM
Show posts by this member only | Post
#5
|
Senior Member
1,108 posts Joined: Jun 2011 |
It never ends. The university teaches you to fish not to eat fish.
In general if you don't use any third party libraries, using 'using namespace std;' is safe. Next somebody will complain why not CODE #include <iostream> main() { } because function/variable declarations/definitions return an int by default. You'll certainly get non error return values half of the time because of the garbage value in the lower half of certain register returned. But not "void main(){...}" of course without certain OS sandbox safeguard. |
|
Jul 23 2015, 09:37 AM
Show posts by this member only | Post
#6
|
Senior Member
1,484 posts Joined: Feb 2012 |
QUOTE(CyrusWong @ Jul 23 2015, 02:03 AM) i currently studying degree in software engineering, 2nd year student, mmu. 3 years i learnt c++ in UTM,my foundation and 1st year degree, all lecturer teaching "using namespace std;" for c++ lol.... is it really a bad practice? lol... maybe becoz lecturer knowledge outdated xD? who know all lecturers oso use "using namespace std;" |
|
Jul 23 2015, 10:54 AM
Show posts by this member only | Post
#7
|
Junior Member
424 posts Joined: Apr 2013 |
it is not a bad practice or whatsoever...
using namespace std just makes your coding easier so that everytime you cin and cout no nid type "std" again and again. it is a mess if you have to write the namespace everytime. |
|
Jul 23 2015, 12:26 PM
Show posts by this member only | Post
#8
|
Junior Member
69 posts Joined: Feb 2005 |
Thanks for giving a damn about good practices. Most don't even indent.
For learners and small projects, this is fine. Less typing, with the added benefit of learning about namespaces! Don't worry about it. As soon as you start importing libraries into your codes, then you should start giving namespaces more attention. Read the Stack Overflow page you linked thoroughly. |
|
Jul 23 2015, 05:10 PM
Show posts by this member only | Post
#9
|
Junior Member
267 posts Joined: Mar 2015 |
thanks for all reply.
|
Topic ClosedOptions
|
Change to: | 0.0123sec
0.56
5 queries
GZIP Disabled
Time is now: 29th March 2024 - 10:20 AM |