Hey guys, I just have a simple (?) question. What difference is there, if any, between cin
and std::cin
(for example)? If the latter is better form, why is it so?
IIMarckus 0 Newbie Poster
Recommended Answers
Jump to Post>using namespace std;
>is required for u 2 be able to use cin only
No, it's not. You have to qualify for the std namespace to use any standard name, but a using directive isn't the only way to do it. In fact, it's probably the worst way to do …
Jump to PostPersonally, using should be use whenever you use those functions in the large amount of time. For example:
using std::cout;
andusing std::cin
are the most common function that you use. These functions should use using globally. For those functions which only use once in the code, should not be …
Jump to PostTo recap, here are the three options using best practices:
#include <iostream> int main() { using namespace std; cout<<"Hello, world!\n"; }
#include <iostream> int main() { using std::cout; cout<<"Hello, world!\n"; }
#include <iostream> int main() { std::cout<<"Hello, world!\n"; }
If you …
Jump to Post>Since these functions are needed to almost every function, why not declare it gloablly?
For the same reason you shouldn't have a global using directive. I doubt anyone will create their own cin and cout, but I see min and max used a lot, yet both of those are standard …
All 14 Replies
JRM 107 Practically a Master Poster
plgriffith 0 Junior Poster
Duoas 1,025 Postaholic Featured Poster
c++ prog 0 Light Poster
JRM 107 Practically a Master Poster
Narue 5,707 Bad Cop Team Colleague
carnage 24 Junior Poster in Training
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
carnage 24 Junior Poster in Training
invisal 381 Search and Destroy
Narue 5,707 Bad Cop Team Colleague
invisal 381 Search and Destroy
Narue 5,707 Bad Cop Team Colleague
IIMarckus 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.