From 782cb579e7649951fa9d3b30ad94e9ce35cf75dd Mon Sep 17 00:00:00 2001 From: neingeist Date: Tue, 19 Aug 2014 08:28:36 +0200 Subject: [PATCH] Do not use namespace using-directives. --- bad_alloc.cpp | 3 ++- list-initializers.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bad_alloc.cpp b/bad_alloc.cpp index 1ef2a17..827f5d5 100644 --- a/bad_alloc.cpp +++ b/bad_alloc.cpp @@ -2,7 +2,8 @@ #include -using namespace std; +using std::cout; +using std::endl; void dr_evil(int counter) { int *array = new int[100000000000/(1+10*counter)]; diff --git a/list-initializers.cpp b/list-initializers.cpp index 6d3b028..743eebb 100644 --- a/list-initializers.cpp +++ b/list-initializers.cpp @@ -4,11 +4,13 @@ #include #include -using namespace std; +using std::map; +using std::pair; +using std::vector; int main() { // notice how the lists are nested to match the templates' parameters: - map>> name_languages_year { + map>> name_languages_year { {"Dennis Ritchie", {{"B", 1969}, {"C", 1973}}}, {"Niklaus Wirth", {{"Pascal", 1970}, {"Modula-2", 1973}, {"Oberon", 1986}}}, @@ -17,7 +19,7 @@ int main() { }; // prints `Pascal': - cout << name_languages_year["Niklaus Wirth"].at(0).first << endl; + std::cout << name_languages_year["Niklaus Wirth"].at(0).first << std::endl; // adds a new entry to the map: name_languages_year["John McCarthy"] = { @@ -25,5 +27,5 @@ int main() { }; // prints 'Lisp': - cout << name_languages_year["John McCarthy"].at(0).first << endl; + std::cout << name_languages_year["John McCarthy"].at(0).first << std::endl; }