Do not place using directives in header files.
Because of how overload resolution works, there is a potential for
using namespace
declarations to at worst
silently change the behavior of the program. By including that header file, you silently introduce a large number of common names which may silently collide with those in your code.
This has been a topic of active discussion on this forum before: see, e.g.,
http://www.cplusplus.com/forum/beginner/212153/#msg992333
Personally, I don't introduce namespace using declarations at global scope, especially not for namespace
std
. Where necessary, I introduce namespace aliases. In my opinion, this reduces ambiguity and results in clearer and less error-prone code.
Use const
where applicable. Consider passing potentially expensive-to-copy objects (like std::string) by reference (const reference here).
1 2 3
|
int write(string const& msg) { ... }
int print(string const& msg) { ... }
std::string input(std::string const& msg) { ... }
| |
Otherwise, it looks good. Be aware that
std::system("pause")
requires the user to be sitting at the computer to un-pause it, which defeats the point of most command line programs, which should be designed to be used non-interactively.