I've been learning C++ for a week or two now, and in the book I've been reading and examples I've been seeing, couldnt you remove all of the std:: at the beginning of each peice of code, and at the beginning but usingnamespace std;? Sorry if theres an obvious reason for doing it your way, I'm just curious.
You definitely could, but it is strongly discouraged for good reason. It takes everything in std and brings it into the global namespace. This generally causes ambiguities (std::count mixing up with your loop counter named count) and a whole host of other problems that can be avoided by not using it. For test programs it's obviously fine, but I and many others try to avoid doing it for the purpose of not getting into the habit of it - it causes real problems in real code, and if you'll find yourself using more duct-tape than C++, or worse, having to go through and remove "using namespace std;" and add "std::" everywhere at a late stage in your project when you have thousands of lines of code.
A 1 degree angle isn't very much and seems harmless, but try going to the moon and being one degree off in your trajectory.
No. You should start out writing std:: before them. It will also help to show you which things are from C++ and which are from C (the C stuff isn't in std). It is better to start a habit early than to try to change a habit later.
The idea is that the examples are easier to read and understand, the side-effect is that people think it is the correct way to write code. You can keep using the same guide, just remember that they don't write std:: because they want you to not get too distracted.
If you really don't want to use std::, then you can replace usingnamespace std; with using std::cout; using std::endl; using std::cin; and explicitly stating any functions/objects that you are bringing in from the std namespace. That'll avoid any accidental conflicts.
Topic archived. No new replies allowed.
You are using a version without Ads of this website. Please, consider donating: