Repository: davisking/dlib (language: python)

Issue:
[Bug]: Conflicts with other codes due to "using namespace std;" in header files
### What Operating System(s) are you seeing this problem on?

Linux (x86-64)

### dlib version

19.24

### Python version

3.12

### Compiler

GCC 13.2

### Expected Behavior

_No response_

### Current Behavior

Several headers of dlib declare "using namespace std;". It creates conflicts with other codes having functions/classes in their own namespace having the same name than the std lib and having the same practice.

It's usually considered a very bad practice in headers: stackoverflow.com/questions/1452721/whats-the-problem-with-using-namespace-std

### Steps to Reproduce

/* This code reproduces the problem */
namespace my_namespace { template <typename T> struct numeric_limits {}; }
using namespace my_namespace;
# include <dlib/optimization.h>
int main(){ return 0; }

### Anything else?

_No response_


Discussion / hints:
I've been checking the header files and, indeed, there are quite a few instances of `using namespace std;`. However, none of them is in the global scope. So they shouldn't interfere.
Either way, if  @davisking is OK, I can remove all those instances and sprinkle a bit of `std::` here and there.

Fix patch:
diff --git a/dlib/any/any_function_abstract.h b/dlib/any/any_function_abstract.h
index 8c0da07365..fc7db2f9a2 100644
--- a/dlib/any/any_function_abstract.h
+++ b/dlib/any/any_function_abstract.h
@@ -46,7 +46,6 @@ namespace dlib
                     #include <iostream>
                     #include <string>
                     #include "dlib/any.h"
-                    using namespace std;
                     void print_message(string str) { cout << str << endl; }
 
                     int main()
diff --git a/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h b/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h
index 68ea5a1350..2a1bef0702 100644
--- a/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h
+++ b/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h
@@ -414,8 +414,6 @@ namespace dlib
         const charT** argv
     )
     {
-        using namespace std;
-
         // make sure there aren't any arguments hanging around from the last time
         // parse was called
         this->argv.clear();
diff --git a/dlib/config_reader/config_reader_thread_safe_1.h b/dlib/config_reader/config_reader_thread_safe_1.h
index 1ad250c99a..6098ad3b45 100644
--- a/dlib/config_reader/config_reader_thread_safe_1.h
+++ b/dlib/config_reader/config_reader_thread_safe_1.h
@@ -426,7 +426,6 @@ namespace dlib
     fill_block_table (
     ) 
     {
-        using namespace std;
         // first empty out the block table
         block_table.reset();
         while (block_table.move_next())
diff --git a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h
index c8bee1e4b2..d4872ea93e 100644
--- a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h
+++ b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h
@@ -122,8 +122,6 @@ namespace dlib
         const std::string& title
     ) const
     {
-        using namespace std;
-
         if (!out)
             throw std::ios::failure("error occurred in cpp_pretty_printer_kernel_1::print");
 
@@ -172,7 +170,7 @@ namespace dlib
 
         int type;
         stack scopes; // a stack to hold old scopes
-        string token, temp;
+        std::string token, temp;
         t.get_token(type,token);
         while (type != tok::END_OF_FILE)
         {
@@ -188,7 +186,7 @@ namespace dlib
                     if (type == tok::WHITE_SPACE)
                     {
                         t.get_token(type,temp);
-                        if (temp.find_first_of("\n\r") != string::npos)
+                        if (temp.find_first_of("\n\r") != std::string::npos)
                             recently_seen_preprocessor = false;
                     }
                     if (t.peek_type() != tok::IDENTIFIER &&
@@ -322,7 +320,7 @@ namespace dlib
                     )
                     {
                         temp = token;
-                        istringstream sin(token);
+                        std::istringstream sin(token);
                         sin >> temp;
                         sin >> temp;
                         sin.get();
@@ -351,7 +349,7 @@ namespace dlib
             case tok::WHITE_SPACE: // -----------------------------------------
                 {
                     out << token;
-                    if (token.find_first_of("\n\r") != string::npos)
+                    if (token.find_first_of("\n\r") != std::string::npos)
                         recently_seen_preprocessor = false;
                 }
                 break;
@@ -497,10 +495,9 @@ namespace dlib
         const std::string& title
     ) const
     {
-        using namespace std;
-        ostringstream sout;
+        std::ostringstream sout;
         print(in,sout,title);
-        istringstream sin(sout.str());
+        std::istringstream sin(sout.str());
         number(sin,out);
     }
 
diff --git a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h
index 5ac894b339..ebba8a80ce 100644
--- a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h
+++ b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h
@@ -122,8 +122,6 @@ namespace dlib
         const std::string& title
     ) const
     {
-        using namespace std;
-
         if (!out)
             throw std::ios::failure("error occurred in cpp_pretty_printer_kernel_2::print");
 
@@ -177,7 +175,7 @@ namespace dlib
 
         int type;
         stack scopes; // a stack to hold old scopes
-        string token, temp;
+        std::string token, temp;
         t.get_token(type,token);
         while (type != tok::END_OF_FILE)
         {
@@ -193,7 +191,7 @@ namespace dlib
                     if (type == tok::WHITE_SPACE)
                     {
                         t.get_token(type,temp);
-                        if (temp.find_first_of("\n\r") != string::npos)
+                        if (temp.find_first_of("\n\r") != std::string::npos)
                             recently_seen_preprocessor = false;
                     }
                     if (t.peek_token() != ";" && t.peek_type() != tok::IDENTIFIER &&
@@ -306,7 +304,7 @@ namespace dlib
             case tok::WHITE_SPACE: // -----------------------------------------
                 {
                     out << token;
-                    if (token.find_first_of("\n\r") != string::npos)
+                    if (token.find_first_of("\n\r") != std::string::npos)
                         recently_seen_preprocessor = false;
                 }
                 break;
@@ -434,10 +432,9 @@ namespace dlib
         const std::string& title
     ) const
     {
-        using namespace std;
-        ostringstream sout;
+        std::ostringstream sout;
         print(in,sout,title);
-        istringstream sin(sout.str());
+        std::istringstream sin(sout.str());
         number(sin,out);
     }
 
diff --git a/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h b/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h
index b26cfc8a54..d93590b035 100644
--- a/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h
+++ b/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h
@@ -380,8 +380,6 @@ namespace dlib
         std::string& token
     )
     {
-        using namespace std;
-
         if (!have_peeked)
         {
 
@@ -501,7 +499,7 @@ namespace dlib
 
                 case '"':
                     {
-                        string temp;                    
+                        std::string temp;                    
                         tokenizer.get_token(type,token);
                         while (type != tok::END_OF_FILE)
                         {
@@ -528,7 +526,7 @@ namespace dlib
 
                 case '\'':
                     {
-                        string temp;                    
+                        std::string temp;                    
                         tokenizer.get_token(type,token);
                         if (type == tok::CHAR && token[0] == '\\')
                         {
@@ -557,7 +555,7 @@ namespace dlib
                                 tokenizer.get_token(type,token);
                                 // this is the start of a line comment
                                 token = "//";
-                                string temp;                    
+                                std::string temp;                    
                                 tokenizer.get_token(type,temp);
                                 while (type != tok::END_OF_FILE)
                                 {
@@ -582,7 +580,7 @@ namespace dlib
                                 tokenizer.get_token(type,token);
                                 // this is the start of a block comment
                                 token = "/*";
-                                string temp;                    
+                                std::string temp;                    
                                 tokenizer.get_token(type,temp);
                                 while (type != tok::END_OF_FILE)
                                 {
diff --git a/dlib/data_io/libsvm_io.h b/dlib/data_io/libsvm_io.h
index f365e82d7d..9383ef6e22 100644
--- a/dlib/data_io/libsvm_io.h
+++ b/dlib/data_io/libsvm_io.h
@@ -30,7 +30,6 @@ namespace dlib
         std::vector<label_type, alloc2>& labels
     )
     {
-        using namespace std;
         typedef typename sample_type::value_type pair_type;
         typedef typename basic_type<typename pair_type::first_type>::type key_type;
         typedef typename pair_type::second_type value_type;
@@ -41,13 +40,13 @@ namespace dlib
         samples.clear();
         labels.clear();
 
-        ifstream fin(file_name.c_str());
+        std::ifstream fin(file_name.c_str());
 
         if (!fin)
             throw sample_data_io_error("Unable to open file " + file_name);
 
-        string line;
-        istringstream sin;
+        std::string line;
+        std::istringstream sin;
         key_type key;
         value_type value;
         label_type label;
@@ -56,12 +55,12 @@ namespace dlib
         while (fin.peek() != EOF)
         {
             ++line_num;
-            getline(fin, line);
+            std::getline(fin, line);
 
-            string::size_type pos = line.find_first_not_of(" \t\r\n");
+            std::string::size_type pos = line.find_first_not_of(" \t\r\n");
 
             // ignore empty lines or comment lines
-            if (pos == string::npos || line[pos] == '#')
+            if (pos == std::string::npos || line[pos] == '#')
                 continue;
 
             sin.clear();
@@ -74,12 +73,12 @@ namespace dlib
                 throw sample_data_io_error("On line: " + cast_to_string(line_num) + ", error while reading file " + file_name );
 
             // eat whitespace
-            sin >> ws;
+            sin >> std::ws;
 
             while (sin.peek() != EOF && sin.peek() != '#')
             {
 
-                sin >> key >> ws;
+                sin >> key >> std::ws;
 
                 // ignore what should be a : character
                 if (sin.get() != ':')
@@ -89,10 +88,10 @@ namespace dlib
 
                 if (sin && value != 0)
                 {
-                    sample.insert(sample.end(), make_pair(key, value));
+                    sample.insert(sample.end(), std::make_pair(key, value));
                 }
 
-                sin >> ws;
+                sin >> std::ws;
             }
 
             samples.push_back(sample);
@@ -202,8 +201,7 @@ namespace dlib
             );
 
 
-        using namespace std;
-        ofstream fout(file_name.c_str());
+        std::ofstream fout(file_name.c_str());
         fout.precision(14);
 
         if (!fout)
@@ -244,8 +242,7 @@ namespace dlib
             << "\n\t labels.size():  " << labels.size()
             );
 
-        using namespace std;
-        ofstream fout(file_name.c_str());
+        std::ofstream fout(file_name.c_str());
         fout.precision(14);
 
         if (!fout)
diff --git a/dlib/dir_nav/dir_nav_kernel_1.h b/dlib/dir_nav/dir_nav_kernel_1.h
index a31f689de8..2d74804645 100644
--- a/dlib/dir_nav/dir_nav_kernel_1.h
+++ b/dlib/dir_nav/dir_nav_kernel_1.h
@@ -390,7 +390,6 @@ namespace dlib
         queue_of_files& files
     ) 
     {
-        using namespace std;
         typedef directory::listing_error listing_error;
         typedef file::private_constructor private_constructor;
 
@@ -402,7 +401,7 @@ namespace dlib
         try
         {
             WIN32_FIND_DATAA data;
-            string path = state.full_name;
+            std::string path = state.full_name;
             // ensure that the path ends with a separator
             if (path[path.size()-1] != directory::get_separator())
                 path += directory::get_separator();
@@ -514,7 +513,6 @@ namespace dlib
         queue_of_dirs& dirs
     ) 
     {
-        using namespace std;
         typedef directory::listing_error listing_error;
         typedef directory::private_constructor private_constructor;
 
@@ -526,7 +524,7 @@ namespace dlib
         try
         {
             WIN32_FIND_DATAA data;
-            string path = state.full_name;
+            std::string path = state.full_name;
             // ensure that the path ends with a separator
             if (path[path.size()-1] != directory::get_separator())
                 path += directory::get_separator();
@@ -541,7 +539,7 @@ namespace dlib
             bool no_more_files = false;
             do
             {
-                string tname(data.cFileName);
+                std::string tname(data.cFileName);
                 if ((data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0 &&
                     tname != "." &&
                     tname != "..")
diff --git a/dlib/dir_nav/dir_nav_kernel_2.h b/dlib/dir_nav/dir_nav_kernel_2.h
index af2f3d5dc9..3560153bbf 100644
--- a/dlib/dir_nav/dir_nav_kernel_2.h
+++ b/dlib/dir_nav/dir_nav_kernel_2.h
@@ -333,8 +333,6 @@ namespace dlib
         queue_of_files& files
     ) 
     {
-        using namespace std;
-
         files.clear();
         if (state.full_name.size() == 0)
             throw directory::listing_error("This directory object currently doesn't represent any directory.");
@@ -345,7 +343,7 @@ namespace dlib
 
         try
         {
-            string path = state.full_name;
+            std::string path = state.full_name;
             // ensure that the path ends with a separator
             if (path[path.size()-1] != directory::get_separator())
                 path += directory::get_separator();
@@ -490,8 +488,6 @@ namespace dlib
         queue_of_dirs& dirs
     ) 
     {
-        using namespace std;
-
         dirs.clear();
         if (state.full_name.size() == 0)
             throw directory::listing_error("This directory object currently doesn't represent any directory.");
@@ -502,7 +498,7 @@ namespace dlib
 
         try
         {
-            string path = state.full_name;
+            std::string path = state.full_name;
             // ensure that the path ends with a separator
             if (path[path.size()-1] != directory::get_separator())
                 path += directory::get_separator();
@@ -540,7 +536,7 @@ namespace dlib
                     continue;
                 }
 
-                string dtemp(data->d_name);
+                std::string dtemp(data->d_name);
                 if (S_ISDIR(buffer.st_mode) &&
                     dtemp != "." &&
                     dtemp != ".." )
diff --git a/dlib/dnn/core.h b/dlib/dnn/core.h
index 6cfb41bc50..dd4f7eb0fb 100644
--- a/dlib/dnn/core.h
+++ b/dlib/dnn/core.h
@@ -3390,9 +3390,8 @@ namespace dlib
                 const auto forward_error = max(abs(mat(ip_out) - mat(subnetwork2.get_output())));
                 if (forward_error > 0.00001)
                 {
-                    using namespace std;
                     sout << "This layer is supposed to support in-place computations but the output of forward_inplace()\n";
-                    sout << "changes when invoked in-place vs. out-of-place. The error was: " << forward_error << endl;
+                    sout << "changes when invoked in-place vs. out-of-place. The error was: " << forward_error << std::endl;
                     return layer_test_results(sout.str()); 
                 }
 
@@ -3422,18 +3421,16 @@ namespace dlib
                     const auto backward_param_error = max(abs(mat(params_grad1) - mat(params_grad2)));
                     if (backward_param_error > 0.00001)
                     {
-                        using namespace std;
                         sout << "This layer is supposed to support in-place computations but the output of backward_inplace()\n";
-                        sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_param_error << endl;
+                        sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_param_error << std::endl;
                         return layer_test_results(sout.str()); 
                     }
                 }
                 const auto backward_data_error = max(abs(mat(data_grad1)-9 - mat(data_grad2)));
                 if (backward_data_error > 0.00001)
                 {
-                    using namespace std;
                     sout << "This layer is supposed to support in-place computations but the output of backward_inplace()\n";
-                    sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_data_error << endl;
+                    sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_data_error << std::endl;
                     return layer_test_results(sout.str()); 
                 }
             }
@@ -3467,11 +3464,10 @@ namespace dlib
                 rs_params.add(std::abs(relative_error));
                 if (std::abs(relative_error) > 0.05 && std::abs(absolute_error) > 0.006)
                 {
-                    using namespace std;
-                    sout << "Gradient error in parameter #" << i <<".  Relative error: "<< relative_error << endl;
-                    sout << "expected derivative: " << reference_derivative << endl;
-                    sout << "output derivative:   " << output_derivative << endl;
-                    sout << "iteration:           " << iter << endl;
+                    sout << "Gradient error in parameter #" << i <<".  Relative error: "<< relative_error << std::endl;
+                    sout << "expected derivative: " << reference_derivative << std::endl;
+                    sout << "output derivative:   " << output_derivative << std::endl;
+                    sout << "iteration:           " << iter << std::endl;
                     return layer_test_results(sout.str()); 
                 }
             }
@@ -3504,11 +3500,10 @@ namespace dlib
                 rs_data.add(std::abs(relative_error));
                 if (std::abs(relative_error) > 0.05 && std::abs(absolute_error) > 0.006)
                 {
-                    using namespace std;
-                    sout << "Gradient error in data variable #" << i <<".  Relative error: "<< relative_error << endl;
-                    sout << "expected derivative: " << reference_derivative << endl;
-                    sout << "output derivative:   " << output_derivative << endl;
-                    sout << "iteration:           " << iter << endl;
+                    sout << "Gradient error in data variable #" << i <<".  Relative error: "<< relative_error << std::endl;
+                    sout << "expected derivative: " << reference_derivative << std::endl;
+                    sout << "output derivative:   " << output_derivative << std::endl;
+                    sout << "iteration:           " << iter << std::endl;
                     return layer_test_results(sout.str()); 
                 }
             }
@@ -3517,14 +3512,12 @@ namespace dlib
 
         if (rs_params.mean() > 0.003)
         {
-            using namespace std;
-            sout << "Average parameter gradient error is somewhat large at: "<< rs_params.mean() << endl;
+            sout << "Average parameter gradient error is somewhat large at: "<< rs_params.mean() << std::endl;
             return layer_test_results(sout.str()); 
         }
         if (rs_data.mean() > 0.003)
         {
-            using namespace std;
-            sout << "Average data gradient error is somewhat large at: "<< rs_data.mean() << endl;
+            sout << "Average data gradient error is somewhat large at: "<< rs_data.mean() << std::endl;
             return layer_test_results(sout.str()); 
         }
 
diff --git a/dlib/dnn/loss.h b/dlib/dnn/loss.h
index 70c316b0fc..a569268398 100644
--- a/dlib/dnn/loss.h
+++ b/dlib/dnn/loss.h
@@ -1843,12 +1843,11 @@ namespace dlib
             use_image_pyramid assume_image_pyramid
         ) const 
         {
-            using namespace std;
             if (!input_layer(net).image_contained_point(input_tensor,center(rect)))
             {
                 std::ostringstream sout;
-                sout << "Encountered a truth rectangle located at " << rect << " that is outside the image." << endl;
-                sout << "The center of each truth rectangle must be within the image." << endl;
+                sout << "Encountered a truth rectangle located at " << rect << " that is outside the image." << std::endl;
+                sout << "The center of each truth rectangle must be within the image." << std::endl;
                 throw impossible_labeling_error(sout.str());
             }
 
diff --git a/dlib/dnn/trainer.h b/dlib/dnn/trainer.h
index 32673d3c13..c329791e78 100644
--- a/dlib/dnn/trainer.h
+++ b/dlib/dnn/trainer.h
@@ -310,15 +310,14 @@ namespace dlib
                 epoch_iteration < max_num_epochs && learning_rate >= min_learning_rate; 
                 ++epoch_iteration)
             {
-                using namespace std::chrono;
-                last_time = system_clock::now();
+                last_time = std::chrono::system_clock::now();
                 clear_average_loss();
                 for (; epoch_pos < data.size() && learning_rate >= min_learning_rate; epoch_pos += mini_batch_size)
                 {
                     if (verbose)
                     {
-                        auto now_time = system_clock::now();
-                        if (now_time-last_time > seconds(20))
+                        auto now_time = std::chrono::system_clock::now();
+                        if (now_time-last_time > std::chrono::seconds(20))
                         {
                             last_time = now_time;
                             auto iter = epoch_iteration + epoch_pos/(double)data.size();
@@ -368,15 +367,14 @@ namespace dlib
                 epoch_iteration < max_num_epochs && learning_rate >= min_learning_rate; 
                 ++epoch_iteration)
             {
-                using namespace std::chrono;
-                last_time = system_clock::now();
+                last_time = std::chrono::system_clock::now();
                 clear_average_loss();
                 for (; epoch_pos < data.size() && learning_rate >= min_learning_rate; epoch_pos += mini_batch_size)
                 {
                     if (verbose)
                     {
-                        auto now_time = system_clock::now();
-                        if (now_time-last_time > seconds(20))
+                        auto now_time = std::chrono::system_clock::now();
+                        if (now_time-last_time > std::chrono::seconds(20))
                         {
                             last_time = now_time;
                             auto iter = epoch_iteration + epoch_pos/(double)data.size();
@@ -1266,9 +1264,8 @@ namespace dlib
         {
             if (verbose)
             {
-                using namespace std::chrono;
-                auto now_time = system_clock::now();
-                if (now_time-last_time > seconds(40))
+                auto now_time = std::chrono::system_clock::now();
+                if (now_time-last_time > std::chrono::seconds(40))
                 {
                     last_time = now_time;
                     std::cout << "step#: " << rpad(cast_to_string(train_one_step_calls),epoch_string_pad) << "  " 
diff --git a/dlib/dnn/utilities.h b/dlib/dnn/utilities.h
index ac7d6c6282..1aaba86ee0 100644
--- a/dlib/dnn/utilities.h
+++ b/dlib/dnn/utilities.h
@@ -50,8 +50,6 @@ namespace dlib
     inline double log1pexp(double x)
     {
         using std::exp;
-        using namespace std; // Do this instead of using std::log1p because some compilers
-                             // error out otherwise (E.g. gcc 4.9 in cygwin)
         if (x <= -37)
             return exp(x);
         else if (-37 < x && x <= 18)
diff --git a/dlib/error.h b/dlib/error.h
index ce9b95b1a8..898019a99a 100644
--- a/dlib/error.h
+++ b/dlib/error.h
@@ -271,7 +271,6 @@ namespace dlib
                           << "To prevent further fatal errors from being ignored this application will be \n"
                           << "terminated immediately and you should go fix this buggy program.\n\n"
                           << "The error message from this fatal error was:\n" << this->what() << "\n\n" << std::endl;
-                using namespace std;
                 assert(false);
                 abort();
             }
diff --git a/dlib/global_optimization/find_max_global.h b/dlib/global_optimization/find_max_global.h
index 8a05ae9050..2c18a2c667 100644
--- a/dlib/global_optimization/find_max_global.h
+++ b/dlib/global_optimization/find_max_global.h
@@ -177,8 +177,10 @@ template <typename T> static auto go(T&& f, const matrix<double, 0, 1>& a) -> de
 
             running_stats_decayed<double> objective_funct_eval_time(functions.size()*5);
             std::mutex eval_time_mutex;
-            using namespace std::chrono;
 
+            using std::chrono::steady_clock;
+            using std::chrono::duration_cast;
+            using std::chrono::nanoseconds;
             const auto time_to_stop = steady_clock::now() + max_runtime;
             //atomic<bool> doesn't support .fetch_or, use std::atomic<int> instead
             std::atomic<int> this_should_stop{false};
diff --git a/dlib/graph_utils/graph_utils.h b/dlib/graph_utils/graph_utils.h
index 81262b7f5c..fd5135cc15 100644
--- a/dlib/graph_utils/graph_utils.h
+++ b/dlib/graph_utils/graph_utils.h
@@ -224,7 +224,6 @@ namespace dlib
                     - #visited[N.index()] == true
         !*/
         {
-            using namespace std;
             if (visited[node.index()] == true)
                 return true;
 
@@ -269,7 +268,6 @@ namespace dlib
                     - #visited[N.index()] == true
         !*/
         {
-            using namespace std;
             if (visited[node.index()] == true)
                 return true;
 
@@ -511,7 +509,6 @@ namespace dlib
         const T& graph
     )
     {
-        using namespace std;
         using namespace graph_helpers;
         std::vector<bool> visited(graph.number_of_nodes(), false);
         std::vector<bool> temp(graph.number_of_nodes(), false);
@@ -544,7 +541,6 @@ namespace dlib
         const T& graph
     )
     {
-        using namespace std;
         using namespace graph_helpers;
         std::vector<bool> visited(graph.number_of_nodes(), false);
 
@@ -860,7 +856,6 @@ namespace dlib
 
 
         using namespace graph_helpers;
-        using namespace std;
         typedef typename set_of_sets_of_int::type set_of_int;
 
         cliques.clear();
diff --git a/dlib/image_keypoint/hessian_pyramid.h b/dlib/image_keypoint/hessian_pyramid.h
index 9d6d8902dd..57b76663d3 100644
--- a/dlib/image_keypoint/hessian_pyramid.h
+++ b/dlib/image_keypoint/hessian_pyramid.h
@@ -461,7 +461,6 @@ namespace dlib
             << "\n\t Invalid arguments to this function"
             << "\n\t threshold: " << threshold 
         );
-        using namespace std;
         using namespace hessian_pyramid_helpers;
 
         result_points.clear();
diff --git a/dlib/image_loader/image_loader.h b/dlib/image_loader/image_loader.h
index e959973f63..8a5cbd9e71 100644
--- a/dlib/image_loader/image_loader.h
+++ b/dlib/image_loader/image_loader.h
@@ -48,9 +48,7 @@ namespace dlib
             unsigned long biCompression;
             unsigned long a, b, c, d, i;
 
-            using namespace std;
-
-            streambuf& in = *in_.rdbuf();
+            std::streambuf& in = *in_.rdbuf();
             unsigned char buf[100];
 
 
diff --git a/dlib/image_processing/detection_template_tools.h b/dlib/image_processing/detection_template_tools.h
index b22c109fe5..09b6e69ff1 100644
--- a/dlib/image_processing/detection_template_tools.h
+++ b/dlib/image_processing/detection_template_tools.h
@@ -32,7 +32,6 @@ namespace dlib
             width*height == area
             width/height == width_to_height_ratio
         */
-        using namespace std;
 
         const int height = (int)std::floor(std::sqrt(area/width_to_height_ratio) + 0.5);
         const int width  = (int)std::floor(area/height + 0.5);
diff --git a/dlib/matrix/matrix.h b/dlib/matrix/matrix.h
index 9073c36b46..2cbebe12ba 100644
--- a/dlib/matrix/matrix.h
+++ b/dlib/matrix/matrix.h
@@ -1995,12 +1995,11 @@ namespace dlib
         const matrix_exp<EXP>& m
     )
     {
-        using namespace std;
-        const streamsize old = out.width();
+        const std::streamsize old = out.width();
 
         // first figure out how wide we should make each field
-        string::size_type w = 0;
-        ostringstream sout;
+        std::string::size_type w = 0;
+        std::ostringstream sout;
         for (long r = 0; r < m.nr(); ++r)
         {
             for (long c = 0; c < m.nc(); ++c)
@@ -2016,7 +2015,7 @@ namespace dlib
         {
             for (long c = 0; c < m.nc(); ++c)
             {
-                out.width(static_cast<streamsize>(w));
+                out.width(static_cast<std::streamsize>(w));
                 out << m(r,c) << " ";
             }
             out << "\n";
diff --git a/dlib/matrix/matrix_lu.h b/dlib/matrix/matrix_lu.h
index 3e49cd6533..faedd53f85 100644
--- a/dlib/matrix/matrix_lu.h
+++ b/dlib/matrix/matrix_lu.h
@@ -101,7 +101,6 @@ namespace dlib
         m(A.nr()),
         n(A.nc())
     {
-        using namespace std;
         using std::abs;
 
         COMPILE_TIME_ASSERT((is_same_type<type, typename EXP::type>::value));
diff --git a/dlib/media/ffmpeg_demuxer.h b/dlib/media/ffmpeg_demuxer.h
index 071f9bfe73..b15acaec90 100644
--- a/dlib/media/ffmpeg_demuxer.h
+++ b/dlib/media/ffmpeg_demuxer.h
@@ -4,6 +4,7 @@
 #ifndef DLIB_FFMPEG_DEMUXER
 #define DLIB_FFMPEG_DEMUXER
 
+#include <chrono>
 #include <queue>
 #include <functional>
 #include <unordered_map>
@@ -995,8 +996,10 @@ namespace dlib
             Callback&& clb
         )
         {
-            using namespace std::chrono;
             using namespace details;
+            using std::chrono::duration_cast;
+            using std::chrono::system_clock;
+            using std::chrono::nanoseconds;
 
             const auto send_packet = [&](extract_state& state)
             {
@@ -1232,8 +1235,8 @@ namespace dlib
 
         inline bool demuxer::open(const args& a)
         {
-            using namespace std::chrono;
             using namespace details;
+            using std::chrono::system_clock;
 
             details::register_ffmpeg();
 
diff --git a/dlib/media/ffmpeg_muxer.h b/dlib/media/ffmpeg_muxer.h
index 75bf6d7de5..2dc4561120 100644
--- a/dlib/media/ffmpeg_muxer.h
+++ b/dlib/media/ffmpeg_muxer.h
@@ -4,6 +4,7 @@
 #ifndef DLIB_VIDEO_MUXER
 #define DLIB_VIDEO_MUXER
 
+#include <chrono>
 #include <queue>
 #include <functional>
 #include <unordered_map>
@@ -1016,7 +1017,6 @@ namespace dlib
             Callback&& clb
         )
         {
-            using namespace std::chrono;
             using namespace details;
 
             if (!is_open())
@@ -1212,8 +1212,8 @@ namespace dlib
 
         inline bool muxer::open(const args& a)
         {
-            using namespace std::chrono;
             using namespace details;
+            using std::chrono::system_clock;
 
             st = {};
             st.args_ = a;
diff --git a/dlib/media/ffmpeg_utils.h b/dlib/media/ffmpeg_utils.h
index f6487041fb..9cdb0ec845 100644
--- a/dlib/media/ffmpeg_utils.h
+++ b/dlib/media/ffmpeg_utils.h
@@ -807,8 +807,8 @@ namespace dlib
                 frame&                  dst
             )
             {
-                using namespace std::chrono;
                 using namespace details;
+                using std::chrono::system_clock;
 
                 DLIB_CASSERT(src.is_audio(), "src.is_audio() == false");
 
@@ -896,7 +896,7 @@ namespace dlib
                 frame&& in
             )
             {
-                using namespace std::chrono;
+                using std::chrono::system_clock;
                 DLIB_ASSERT(in.is_audio(), "this isn't an audio frame");
 
                 std::vector<frame> outs;
diff --git a/dlib/optimization/elastic_net.h b/dlib/optimization/elastic_net.h
index 6c4b6d0b43..7b77a4eb8d 100644
--- a/dlib/optimization/elastic_net.h
+++ b/dlib/optimization/elastic_net.h
@@ -297,11 +297,10 @@ namespace dlib
 
                 if (verbose)
                 {
-                    using namespace std;
-                    cout << "gap:         " << PG_max - PG_min << endl;
-                    cout << "active_size: " << active_size << endl;
-                    cout << "iter:        " << iter << endl;
-                    cout << endl;
+                    std::cout << "gap:         " << PG_max - PG_min << std::endl;
+                    std::cout << "active_size: " << active_size << std::endl;
+                    std::cout << "iter:        " << iter << std::endl;
+                    std::cout << std::endl;
                 }
 
                 if (PG_max - PG_min <= eps)
diff --git a/dlib/optimization/optimization_solve_qp2_using_smo.h b/dlib/optimization/optimization_solve_qp2_using_smo.h
index 88cad0cf3c..787d4ae416 100644
--- a/dlib/optimization/optimization_solve_qp2_using_smo.h
+++ b/dlib/optimization/optimization_solve_qp2_using_smo.h
@@ -281,7 +281,6 @@ namespace dlib
             long& j_out
         ) const
         {
-            using namespace std;
             long ip = 0;
             long jp = 0;
             long in = 0;
@@ -291,10 +290,10 @@ namespace dlib
             typedef typename colm_exp<EXP>::type col_type;
             typedef typename diag_exp<EXP>::type diag_type;
 
-            scalar_type ip_val = -numeric_limits<scalar_type>::infinity();
-            scalar_type jp_val = numeric_limits<scalar_type>::infinity();
-            scalar_type in_val = -numeric_limits<scalar_type>::infinity();
-            scalar_type jn_val = numeric_limits<scalar_type>::infinity();
+            scalar_type ip_val = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type jp_val = std::numeric_limits<scalar_type>::infinity();
+            scalar_type in_val = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type jn_val = std::numeric_limits<scalar_type>::infinity();
 
             // loop over the alphas and find the maximum ip and in indices.
             for (long i = 0; i < alpha.nr(); ++i)
@@ -323,8 +322,8 @@ namespace dlib
                 }
             }
 
-            scalar_type Mp = numeric_limits<scalar_type>::infinity();
-            scalar_type Mn = numeric_limits<scalar_type>::infinity();
+            scalar_type Mp = std::numeric_limits<scalar_type>::infinity();
+            scalar_type Mn = std::numeric_limits<scalar_type>::infinity();
 
             // Pick out the columns and diagonal of Q we need below.  Doing
             // it this way is faster if Q is actually a symmetric_matrix_cache
diff --git a/dlib/optimization/optimization_solve_qp3_using_smo.h b/dlib/optimization/optimization_solve_qp3_using_smo.h
index 617ecc408c..eb83fc85d1 100644
--- a/dlib/optimization/optimization_solve_qp3_using_smo.h
+++ b/dlib/optimization/optimization_solve_qp3_using_smo.h
@@ -218,17 +218,14 @@ namespace dlib
             long& j_out
         ) const
         {
-            using namespace std;
-
             long ip = 0;
             long jp = 0;
 
-
             typedef typename colm_exp<EXP>::type col_type;
             typedef typename diag_exp<EXP>::type diag_type;
 
-            scalar_type ip_val = -numeric_limits<scalar_type>::infinity();
-            scalar_type jp_val = numeric_limits<scalar_type>::infinity();
+            scalar_type ip_val = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type jp_val = std::numeric_limits<scalar_type>::infinity();
 
             // loop over the alphas and find the maximum ip and in indices.
             for (long i = 0; i < alpha.nr(); ++i)
@@ -257,7 +254,7 @@ namespace dlib
                 }
             }
 
-            scalar_type Mp = -numeric_limits<scalar_type>::infinity();
+            scalar_type Mp = -std::numeric_limits<scalar_type>::infinity();
 
             // Pick out the column and diagonal of Q we need below.  Doing
             // it this way is faster if Q is actually a symmetric_matrix_cache
diff --git a/dlib/optimization/optimization_solve_qp_using_smo.h b/dlib/optimization/optimization_solve_qp_using_smo.h
index c942d064a4..339fe77ce0 100644
--- a/dlib/optimization/optimization_solve_qp_using_smo.h
+++ b/dlib/optimization/optimization_solve_qp_using_smo.h
@@ -200,7 +200,6 @@ namespace dlib
         }
 
         /*
-        using namespace std;
         cout << "SMO: " << endl;
         cout << "   duality gap: "<< trans(alpha)*df - C*min(df) << endl;
         cout << "   KKT gap:     "<< big-little << endl;
@@ -394,7 +393,6 @@ namespace dlib
         }
 
         /*
-        using namespace std;
         cout << "SMO: " << endl;
         cout << "   duality gap: "<< trans(alpha)*df - C*min(df) << endl;
         cout << "   KKT gap:     "<< big-little << endl;
diff --git a/dlib/optimization/optimization_stop_strategies.h b/dlib/optimization/optimization_stop_strategies.h
index a0243cacf4..ff64ef8a86 100644
--- a/dlib/optimization/optimization_stop_strategies.h
+++ b/dlib/optimization/optimization_stop_strategies.h
@@ -60,8 +60,7 @@ namespace dlib
         {
             if (_verbose)
             {
-                using namespace std;
-                cout << "iteration: " << _cur_iter << "   objective: " << funct_value << endl;
+                std::cout << "iteration: " << _cur_iter << "   objective: " << funct_value << std::endl;
             }
 
             ++_cur_iter;
@@ -139,8 +138,7 @@ namespace dlib
         {
             if (_verbose)
             {
-                using namespace std;
-                cout << "iteration: " << _cur_iter << "   objective: " << funct_value << "   gradient norm: " << length(funct_derivative) << endl;
+                std::cout << "iteration: " << _cur_iter << "   objective: " << funct_value << "   gradient norm: " << length(funct_derivative) << std::endl;
             }
 
             ++_cur_iter;
diff --git a/dlib/pixel.h b/dlib/pixel.h
index f995dd477f..d53a0fbe18 100644
--- a/dlib/pixel.h
+++ b/dlib/pixel.h
@@ -1068,7 +1068,6 @@ namespace dlib
         {
             double themin,themax,delta;
             HSL c2;
-            using namespace std;
 
             themin = std::min(c1.r,std::min(c1.g,c1.b));
             themax = std::max(c1.r,std::max(c1.g,c1.b));
@@ -1099,7 +1098,6 @@ namespace dlib
         inline COLOUR HSL2RGB(HSL c1)
         {
             COLOUR c2,sat,ctmp;
-            using namespace std;
 
             if (c1.h < 120) {
                 sat.r = (120 - c1.h) / 60.0;
@@ -1267,26 +1265,25 @@ namespace dlib
         inline Lab RGB2Lab(COLOUR c1)
         {
             Lab c2;
-            using namespace std;
 
             double var_R = c1.r;
             double var_G = c1.g;
             double var_B = c1.b;
 
             if (var_R > 0.04045) {
-                var_R = pow(((var_R + 0.055) / 1.055), 2.4);
+                var_R = std::pow(((var_R + 0.055) / 1.055), 2.4);
             } else {
                 var_R = var_R / 12.92;
             }
 
             if (var_G > 0.04045) {
-                var_G = pow(((var_G + 0.055) / 1.055), 2.4);
+                var_G = std::pow(((var_G + 0.055) / 1.055), 2.4);
             } else {
                 var_G = var_G / 12.92;
             }
 
             if (var_B > 0.04045) {
-                var_B = pow(((var_B + 0.055) / 1.055), 2.4);
+                var_B = std::pow(((var_B + 0.055) / 1.055), 2.4);
             } else {
                 var_B = var_B / 12.92;
             }
@@ -1305,21 +1302,21 @@ namespace dlib
             double var_Z = Z / 108.883;
 
             if (var_X > 0.008856) {
-                var_X = pow(var_X, (1.0 / 3));
+                var_X = std::pow(var_X, (1.0 / 3));
             }
             else {
                 var_X = (7.787 * var_X) + (16.0 / 116);
             }
 
             if (var_Y > 0.008856) {
-                var_Y = pow(var_Y, (1.0 / 3));
+                var_Y = std::pow(var_Y, (1.0 / 3));
             }
             else {
                 var_Y = (7.787 * var_Y) + (16.0 / 116);
             }
 
             if (var_Z > 0.008856) {
-                var_Z = pow(var_Z, (1.0 / 3));
+                var_Z = std::pow(var_Z, (1.0 / 3));
             }
             else {
                 var_Z = (7.787 * var_Z) + (16.0 / 116);
@@ -1342,26 +1339,25 @@ namespace dlib
         */
         inline COLOUR Lab2RGB(Lab c1) {
             COLOUR c2;
-            using namespace std;
 
             double var_Y = (c1.l + 16) / 116.0;
             double var_X = (c1.a / 500.0) + var_Y;
             double var_Z = var_Y - (c1.b / 200);
 
-            if (pow(var_Y, 3) > 0.008856) {
-                var_Y = pow(var_Y, 3);
+            if (std::pow(var_Y, 3) > 0.008856) {
+                var_Y = std::pow(var_Y, 3);
             } else {
                 var_Y = (var_Y - 16.0 / 116) / 7.787;
             }
 
-            if (pow(var_X, 3) > 0.008856) {
-                var_X = pow(var_X, 3);
+            if (std::pow(var_X, 3) > 0.008856) {
+                var_X = std::pow(var_X, 3);
             } else {
                 var_X = (var_X - 16.0 / 116) / 7.787;
             }
 
-            if (pow(var_Z, 3) > 0.008856) {
-                var_Z = pow(var_Z, 3);
+            if (std::pow(var_Z, 3) > 0.008856) {
+                var_Z = std::pow(var_Z, 3);
             } else {
                 var_Z = (var_Z - 16.0 / 116) / 7.787;
             }
@@ -1379,19 +1375,19 @@ namespace dlib
             double var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570;
 
             if (var_R > 0.0031308) {
-                var_R = 1.055 * pow(var_R, (1 / 2.4)) - 0.055;
+                var_R = 1.055 * std::pow(var_R, (1 / 2.4)) - 0.055;
             } else {
                 var_R = 12.92 * var_R;
             }
 
             if (var_G > 0.0031308) {
-                var_G = 1.055 * pow(var_G, (1 / 2.4)) - 0.055;
+                var_G = 1.055 * std::pow(var_G, (1 / 2.4)) - 0.055;
             } else {
                 var_G = 12.92 * var_G;
             }
 
             if (var_B > 0.0031308) {
-                var_B = 1.055 * pow(var_B, (1 / 2.4)) - 0.055;
+                var_B = 1.055 * std::pow(var_B, (1 / 2.4)) - 0.055;
             } else {
                 var_B = 12.92 * var_B;
             }
diff --git a/dlib/string/string.h b/dlib/string/string.h
index 2c26021988..bf300fd350 100644
--- a/dlib/string/string.h
+++ b/dlib/string/string.h
@@ -290,8 +290,7 @@ namespace dlib
             const std::basic_string<charT,traits,alloc>& str
         )
         {
-            using namespace std;
-            basic_istringstream<charT,traits,alloc> sin(str);
+            std::basic_istringstream<charT,traits,alloc> sin(str);
             T temp;
             sin >> temp;
             if (!sin) throw string_cast_error(narrow(str));
@@ -324,7 +323,6 @@ namespace dlib
             const std::basic_string<charT,traits,alloc>& str
         )
         {
-            using namespace std;
             if (str.size() == 1 && str[0] == '1')
                 return true;
             if (str.size() == 1 && str[0] == '0')
@@ -347,14 +345,13 @@ namespace dlib
             const std::basic_string<charT,traits,alloc>& str        \
         )                                                           \
         {                                                           \
-            using namespace std;                                    \
-            basic_istringstream<charT,traits,alloc> sin(str);       \
+            std::basic_istringstream<charT,traits,alloc> sin(str);  \
             type temp;                                              \
             if (str.size() > 2 && str[0] == _dT(charT,'0') && str[1] == _dT(charT,'x'))   \
-                sin >> hex >> temp;                                 \
+                sin >> std::hex >> temp;                            \
             else                                                    \
                 sin >> temp;                                        \
-            if (!sin) throw string_cast_error(narrow(str));                 \
+            if (!sin) throw string_cast_error(narrow(str));         \
             if (sin.get() != std::char_traits<charT>::eof()) throw string_cast_error(narrow(str));     \
             return temp;                                            \
         }                                                           \
@@ -508,23 +505,21 @@ namespace dlib
                  << "\n\trest_pad:     " << rest_pad
                  << "\n\tmax_per_line: " << max_per_line  );
 
-        using namespace std;
-
-        basic_ostringstream<charT,traits,alloc> sout;
-        basic_istringstream<charT,traits,alloc> sin(str);
+        std::basic_ostringstream<charT,traits,alloc> sout;
+        std::basic_istringstream<charT,traits,alloc> sin(str);
 
         for (unsigned long i = 0; i < rest_pad; ++i)
             sout << _dT(charT," ");
-        const basic_string<charT,traits,alloc> pad(sout.str());
+        const std::basic_string<charT,traits,alloc> pad(sout.str());
         sout.str(_dT(charT,""));
 
         for (unsigned long i = 0; i < first_pad; ++i)
             sout << _dT(charT," ");
 
 
-        typename basic_string<charT,traits,alloc>::size_type remaining = max_per_line - rest_pad;
+        typename std::basic_string<charT,traits,alloc>::size_type remaining = max_per_line - rest_pad;
 
-        basic_string<charT,traits,alloc> temp;
+        std::basic_string<charT,traits,alloc> temp;
 
         sin >> temp;
         while (sin)
@@ -533,7 +528,7 @@ namespace dlib
             {
                 if (temp.size() + rest_pad >= max_per_line)
                 {
-                    string::size_type i = 0;
+                    std::string::size_type i = 0;
                     for (; i < temp.size(); ++i)
                     {
                         sout << temp[i];
diff --git a/dlib/svm/feature_ranking.h b/dlib/svm/feature_ranking.h
index f6324fe3d3..c1275c27f1 100644
--- a/dlib/svm/feature_ranking.h
+++ b/dlib/svm/feature_ranking.h
@@ -69,8 +69,6 @@ namespace dlib
         }
 
 
-        using namespace std;
-
         for (long i = results.nr()-1; i >= 0; --i)
         {
             long worst_feature_idx = 0;
@@ -189,8 +187,6 @@ namespace dlib
         matrix<scalar_type,sample_matrix_type::type::NR,1,mm> mask(samples(0).nr());
         set_all_elements(mask,0);
 
-        using namespace std;
-
         for (long i = 0; i < results.nr(); ++i)
         {
             long best_feature_idx = 0;
@@ -332,8 +328,6 @@ namespace dlib
                 double gamma
             ) const
             {
-                using namespace std;
-
                 // we are doing the optimization in log space so don't forget to convert back to normal space
                 gamma = std::exp(gamma);
 
@@ -347,8 +341,8 @@ namespace dlib
 
                 if (verbose)
                 {
-                    cout << "\rChecking goodness of gamma = " << gamma << ".  Goodness = " 
-                         << temp << "                    " << flush;
+                    std::cout << "\rChecking goodness of gamma = " << gamma << ".  Goodness = " 
+                         << temp << "                    " << std::flush;
                 }
                 return temp;
             }
@@ -372,11 +366,9 @@ namespace dlib
             bool verbose
         )
         {
-            using namespace std;
-
             if (verbose)
             {
-                cout << endl;
+                std::cout << std::endl;
             }
 
             test<sample_matrix_type, label_matrix_type> funct(samples, labels, num_sv, verbose);
@@ -385,8 +377,8 @@ namespace dlib
             
             if (verbose)
             {
-                cout << "\rBest gamma = " << std::exp(best_gamma) << ".  Goodness = " 
-                    << goodness << "                    " << endl;
+                std::cout << "\rBest gamma = " << std::exp(best_gamma) << ".  Goodness = " 
+                    << goodness << "                    " << std::endl;
             }
 
             return std::exp(best_gamma);
diff --git a/dlib/svm/rr_trainer.h b/dlib/svm/rr_trainer.h
index 09177217e3..7ea328d76c 100644
--- a/dlib/svm/rr_trainer.h
+++ b/dlib/svm/rr_trainer.h
@@ -394,12 +394,11 @@ namespace dlib
 
             if (verbose && did_loov)
             {
-                using namespace std;
-                cout << "Using lambda:             " << the_lambda << endl;
+                std::cout << "Using lambda:             " << the_lambda << std::endl;
                 if (use_regression_loss)
-                    cout << "LOO Mean Squared Error:   " << best_looe << endl;
+                    std::cout << "LOO Mean Squared Error:   " << best_looe << std::endl;
                 else
-                    cout << "LOO Classification Error: " << best_looe << endl;
+                    std::cout << "LOO Classification Error: " << best_looe << std::endl;
             }
 
             // convert w into a proper decision function
diff --git a/dlib/svm/structural_svm_object_detection_problem.h b/dlib/svm/structural_svm_object_detection_problem.h
index 1c54a42b11..ee9ed6a1cd 100644
--- a/dlib/svm/structural_svm_object_detection_problem.h
+++ b/dlib/svm/structural_svm_object_detection_problem.h
@@ -230,8 +230,7 @@ namespace dlib
                         const double match_amount = area_overlap/(double)( mapped_rects[i]+mapped_rects[j]).area();
                         const double overlap_amount = area_overlap/std::min(mapped_rects[i].area(),mapped_rects[j].area());
 
-                        using namespace std;
-                        ostringstream sout;
+                        std::ostringstream sout;
                         sout << "An impossible set of object labels was detected. This is happening because ";
                         sout << "the truth labels for an image contain rectangles which overlap according to the ";
                         sout << "test_box_overlap object supplied for non-max suppression.  To resolve this, you ";
@@ -239,16 +238,16 @@ namespace dlib
                         sout << "overlapping or adjust the truth rectangles in your training dataset. ";
 
                         // make sure the above string fits nicely into a command prompt window.
-                        string temp = sout.str();
-                        sout.str(""); sout << wrap_string(temp,0,0) << endl << endl;
+                        std::string temp = sout.str();
+                        sout.str(""); sout << wrap_string(temp,0,0) << std::endl << std::endl;
 
 
-                        sout << "image index: "<< idx << endl;
+                        sout << "image index: "<< idx << std::endl;
                         sout << "The offending rectangles are:\n";
-                        sout << "rect1: "<< mapped_rects[i] << endl;
-                        sout << "rect2: "<< mapped_rects[j] << endl;
-                        sout << "match amount:   " << match_amount << endl;
-                        sout << "overlap amount: " << overlap_amount << endl;
+                        sout << "rect1: "<< mapped_rects[i] << std::endl;
+                        sout << "rect2: "<< mapped_rects[j] << std::endl;
+                        sout << "match amount:   " << match_amount << std::endl;
+                        sout << "overlap amount: " << overlap_amount << std::endl;
                         throw dlib::impossible_labeling_error(sout.str());
                     }
                 }
@@ -262,8 +261,7 @@ namespace dlib
                 const double total_area = (truth_object_detections[idx][i].get_rect() + mapped_rects[i]).area();
                 if (area/total_area <= match_eps)
                 {
-                    using namespace std;
-                    ostringstream sout;
+                    std::ostringstream sout;
                     sout << "An impossible set of object labels was detected.  This is happening because ";
                     sout << "none of the object locations checked by the supplied image scanner is a close ";
                     sout << "enough match to one of the truth boxes in your training dataset.  To resolve this ";
@@ -278,18 +276,18 @@ namespace dlib
 
 
                     // make sure the above string fits nicely into a command prompt window.
-                    string temp = sout.str();
-                    sout.str(""); sout << wrap_string(temp,0,0) << endl << endl;
-
-                    sout << "image index              "<< idx << endl;
-                    sout << "match_eps:               "<< match_eps << endl;
-                    sout << "best possible match:     "<< area/total_area << endl;
-                    sout << "truth rect:              "<< truth_object_detections[idx][i].get_rect() << endl;
-                    sout << "truth rect width/height: "<< truth_object_detections[idx][i].get_rect().width()/(double)truth_object_detections[idx][i].get_rect().height() << endl;
-                    sout << "truth rect area:         "<< truth_object_detections[idx][i].get_rect().area() << endl;
-                    sout << "nearest detection template rect:              "<< mapped_rects[i] << endl;
-                    sout << "nearest detection template rect width/height: "<< mapped_rects[i].width()/(double)mapped_rects[i].height() << endl;
-                    sout << "nearest detection template rect area:         "<< mapped_rects[i].area() << endl;
+                    std::string temp = sout.str();
+                    sout.str(""); sout << wrap_string(temp,0,0) << std::endl << std::endl;
+
+                    sout << "image index              "<< idx << std::endl;
+                    sout << "match_eps:               "<< match_eps << std::endl;
+                    sout << "best possible match:     "<< area/total_area << std::endl;
+                    sout << "truth rect:              "<< truth_object_detections[idx][i].get_rect() << std::endl;
+                    sout << "truth rect width/height: "<< truth_object_detections[idx][i].get_rect().width()/(double)truth_object_detections[idx][i].get_rect().height() << std::endl;
+                    sout << "truth rect area:         "<< truth_object_detections[idx][i].get_rect().area() << std::endl;
+                    sout << "nearest detection template rect:              "<< mapped_rects[i] << std::endl;
+                    sout << "nearest detection template rect width/height: "<< mapped_rects[i].width()/(double)mapped_rects[i].height() << std::endl;
+                    sout << "nearest detection template rect area:         "<< mapped_rects[i].area() << std::endl;
                     throw dlib::impossible_labeling_error(sout.str());
                 }
 
diff --git a/dlib/svm/structural_svm_problem.h b/dlib/svm/structural_svm_problem.h
index 3a73457b9f..b1f045449a 100644
--- a/dlib/svm/structural_svm_problem.h
+++ b/dlib/svm/structural_svm_problem.h
@@ -434,27 +434,26 @@ namespace dlib
         {
             if (verbose)
             {
-                using namespace std;
                 if (nuclear_norm_regularizers.size() != 0)
                 {
-                    cout << "objective:             " << current_objective_value << endl;
-                    cout << "objective gap:         " << current_error_gap << endl;
-                    cout << "risk:                  " << current_risk_value-nuclear_norm_part << endl;
-                    cout << "risk+nuclear norm:     " << current_risk_value << endl;
-                    cout << "risk+nuclear norm gap: " << current_risk_gap << endl;
-                    cout << "num planes:            " << num_cutting_planes << endl;
-                    cout << "iter:                  " << num_iterations << endl;
+                    std::cout << "objective:             " << current_objective_value << std::endl;
+                    std::cout << "objective gap:         " << current_error_gap << std::endl;
+                    std::cout << "risk:                  " << current_risk_value-nuclear_norm_part << std::endl;
+                    std::cout << "risk+nuclear norm:     " << current_risk_value << std::endl;
+                    std::cout << "risk+nuclear norm gap: " << current_risk_gap << std::endl;
+                    std::cout << "num planes:            " << num_cutting_planes << std::endl;
+                    std::cout << "iter:                  " << num_iterations << std::endl;
                 }
                 else
                 {
-                    cout << "objective:     " << current_objective_value << endl;
-                    cout << "objective gap: " << current_error_gap << endl;
-                    cout << "risk:          " << current_risk_value << endl;
-                    cout << "risk gap:      " << current_risk_gap << endl;
-                    cout << "num planes:    " << num_cutting_planes << endl;
-                    cout << "iter:          " << num_iterations << endl;
+                    std::cout << "objective:     " << current_objective_value << std::endl;
+                    std::cout << "objective gap: " << current_error_gap << std::endl;
+                    std::cout << "risk:          " << current_risk_value << std::endl;
+                    std::cout << "risk gap:      " << current_risk_gap << std::endl;
+                    std::cout << "num planes:    " << num_cutting_planes << std::endl;
+                    std::cout << "iter:          " << num_iterations << std::endl;
                 }
-                cout << endl;
+                std::cout << std::endl;
             }
 
             if (num_iterations >= max_iterations)
diff --git a/dlib/svm/svm_c_linear_dcd_trainer.h b/dlib/svm/svm_c_linear_dcd_trainer.h
index 039b70993e..6ac0e7ae75 100644
--- a/dlib/svm/svm_c_linear_dcd_trainer.h
+++ b/dlib/svm/svm_c_linear_dcd_trainer.h
@@ -619,11 +619,10 @@ namespace dlib
 
                 if (verbose)
                 {
-                    using namespace std;
-                    cout << "gap:         " << PG_max - PG_min << endl;
-                    cout << "active_size: " << active_size << endl;
-                    cout << "iter:        " << iter << endl;
-                    cout << endl;
+                    std::cout << "gap:         " << PG_max - PG_min << std::endl;
+                    std::cout << "active_size: " << active_size << std::endl;
+                    std::cout << "iter:        " << iter << std::endl;
+                    std::cout << std::endl;
                 }
 
                 if (PG_max - PG_min <= eps)
diff --git a/dlib/svm/svm_c_linear_trainer.h b/dlib/svm/svm_c_linear_trainer.h
index 3764ddd8aa..e6c9730ce0 100644
--- a/dlib/svm/svm_c_linear_trainer.h
+++ b/dlib/svm/svm_c_linear_trainer.h
@@ -87,14 +87,13 @@ namespace dlib
         {
             if (be_verbose)
             {
-                using namespace std;
-                cout << "objective:     " << current_objective_value << endl;
-                cout << "objective gap: " << current_error_gap << endl;
-                cout << "risk:          " << current_risk_value << endl;
-                cout << "risk gap:      " << current_risk_gap << endl;
-                cout << "num planes:    " << num_cutting_planes << endl;
-                cout << "iter:          " << num_iterations << endl;
-                cout << endl;
+                std::cout << "objective:     " << current_objective_value << std::endl;
+                std::cout << "objective gap: " << current_error_gap << std::endl;
+                std::cout << "risk:          " << current_risk_value << std::endl;
+                std::cout << "risk gap:      " << current_risk_gap << std::endl;
+                std::cout << "num planes:    " << num_cutting_planes << std::endl;
+                std::cout << "iter:          " << num_iterations << std::endl;
+                std::cout << std::endl;
             }
 
             if (num_iterations >= max_iterations)
diff --git a/dlib/svm/svm_c_trainer.h b/dlib/svm/svm_c_trainer.h
index 445dbf69c7..b2c9d7dff2 100644
--- a/dlib/svm/svm_c_trainer.h
+++ b/dlib/svm/svm_c_trainer.h
@@ -277,12 +277,11 @@ namespace dlib
             scalar_type& b
         ) const
         {
-            using namespace std;
             long num_free = 0;
             scalar_type sum_free = 0;
 
-            scalar_type upper_bound = -numeric_limits<scalar_type>::infinity();
-            scalar_type lower_bound = numeric_limits<scalar_type>::infinity();
+            scalar_type upper_bound = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type lower_bound = std::numeric_limits<scalar_type>::infinity();
 
             for(long i = 0; i < alpha.nr(); ++i)
             {
diff --git a/dlib/svm/svm_nu_trainer.h b/dlib/svm/svm_nu_trainer.h
index cf041b2354..59f49ab208 100644
--- a/dlib/svm/svm_nu_trainer.h
+++ b/dlib/svm/svm_nu_trainer.h
@@ -233,16 +233,15 @@ namespace dlib
             scalar_type& b
         ) const
         {
-            using namespace std;
             long num_p_free = 0;
             long num_n_free = 0;
             scalar_type sum_p_free = 0;
             scalar_type sum_n_free = 0;
 
-            scalar_type upper_bound_p = -numeric_limits<scalar_type>::infinity();
-            scalar_type upper_bound_n = -numeric_limits<scalar_type>::infinity();
-            scalar_type lower_bound_p = numeric_limits<scalar_type>::infinity();
-            scalar_type lower_bound_n = numeric_limits<scalar_type>::infinity();
+            scalar_type upper_bound_p = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type upper_bound_n = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type lower_bound_p = std::numeric_limits<scalar_type>::infinity();
+            scalar_type lower_bound_n = std::numeric_limits<scalar_type>::infinity();
 
             for(long i = 0; i < alpha.nr(); ++i)
             {
diff --git a/dlib/svm/svm_one_class_trainer.h b/dlib/svm/svm_one_class_trainer.h
index be3cc8caf3..6a5c55e951 100644
--- a/dlib/svm/svm_one_class_trainer.h
+++ b/dlib/svm/svm_one_class_trainer.h
@@ -224,7 +224,6 @@ namespace dlib
             scalar_type& rho
         ) const
         {
-            using namespace std;
             long num_p_free = 0;
             scalar_type sum_p_free = 0;
 
diff --git a/dlib/svm/svm_rank_trainer.h b/dlib/svm/svm_rank_trainer.h
index 0be737f485..03a7aeefa1 100644
--- a/dlib/svm/svm_rank_trainer.h
+++ b/dlib/svm/svm_rank_trainer.h
@@ -72,14 +72,13 @@ namespace dlib
         {
             if (be_verbose)
             {
-                using namespace std;
-                cout << "objective:     " << current_objective_value << endl;
-                cout << "objective gap: " << current_error_gap << endl;
-                cout << "risk:          " << current_risk_value << endl;
-                cout << "risk gap:      " << current_risk_gap << endl;
-                cout << "num planes:    " << num_cutting_planes << endl;
-                cout << "iter:          " << num_iterations << endl;
-                cout << endl;
+                std::cout << "objective:     " << current_objective_value << std::endl;
+                std::cout << "objective gap: " << current_error_gap << std::endl;
+                std::cout << "risk:          " << current_risk_value << std::endl;
+                std::cout << "risk gap:      " << current_risk_gap << std::endl;
+                std::cout << "num planes:    " << num_cutting_planes << std::endl;
+                std::cout << "iter:          " << num_iterations << std::endl;
+                std::cout << std::endl;
             }
 
             if (num_iterations >= max_iterations)
diff --git a/dlib/svm/svr_linear_trainer.h b/dlib/svm/svr_linear_trainer.h
index 27ce5b52a1..0708c29383 100644
--- a/dlib/svm/svr_linear_trainer.h
+++ b/dlib/svm/svr_linear_trainer.h
@@ -76,14 +76,13 @@ namespace dlib
             current_risk_gap /= samples.size();
             if (be_verbose)
             {
-                using namespace std;
-                cout << "objective:     " << current_objective_value << endl;
-                cout << "objective gap: " << current_error_gap << endl;
-                cout << "risk:          " << current_risk_value << endl;
-                cout << "risk gap:      " << current_risk_gap << endl;
-                cout << "num planes:    " << num_cutting_planes << endl;
-                cout << "iter:          " << num_iterations << endl;
-                cout << endl;
+                std::cout << "objective:     " << current_objective_value << std::endl;
+                std::cout << "objective gap: " << current_error_gap << std::endl;
+                std::cout << "risk:          " << current_risk_value << std::endl;
+                std::cout << "risk gap:      " << current_risk_gap << std::endl;
+                std::cout << "num planes:    " << num_cutting_planes << std::endl;
+                std::cout << "iter:          " << num_iterations << std::endl;
+                std::cout << std::endl;
             }
 
             if (num_iterations >= max_iterations)
diff --git a/dlib/svm/svr_trainer.h b/dlib/svm/svr_trainer.h
index bc6378a200..6560b1513a 100644
--- a/dlib/svm/svr_trainer.h
+++ b/dlib/svm/svr_trainer.h
@@ -312,12 +312,11 @@ namespace dlib
             scalar_type& b
         ) const
         {
-            using namespace std;
             long num_free = 0;
             scalar_type sum_free = 0;
 
-            scalar_type upper_bound = -numeric_limits<scalar_type>::infinity();
-            scalar_type lower_bound = numeric_limits<scalar_type>::infinity();
+            scalar_type upper_bound = -std::numeric_limits<scalar_type>::infinity();
+            scalar_type lower_bound = std::numeric_limits<scalar_type>::infinity();
 
             find_min_and_max(df, upper_bound, lower_bound);
 
diff --git a/dlib/threads/thread_pool_extension.h b/dlib/threads/thread_pool_extension.h
index 06d091c874..bd459ed6f8 100644
--- a/dlib/threads/thread_pool_extension.h
+++ b/dlib/threads/thread_pool_extension.h
@@ -516,14 +516,12 @@ namespace dlib
             {
                 std::cerr << "An unhandled exception was inside a dlib::thread_pool when it was destructed." << std::endl;
                 std::cerr << "It's what string is: \n" << e.what() << std::endl;
-                using namespace std;
                 assert(false);
                 abort();
             }
             catch (...)
             {
                 std::cerr << "An unhandled exception was inside a dlib::thread_pool when it was destructed." << std::endl;
-                using namespace std;
                 assert(false);
                 abort();
             }
diff --git a/dlib/time_this.h b/dlib/time_this.h
index aec0d2de81..ac9bb355d1 100644
--- a/dlib/time_this.h
+++ b/dlib/time_this.h
@@ -13,7 +13,7 @@
         auto _tt_start = std::chrono::high_resolution_clock::now();                                             \
         {_tt_op;}                                                                                               \
         auto _tt_stop = std::chrono::high_resolution_clock::now();                                              \
-        auto _tt_thetime = _tt_stop-_tt_start;                                                                          \
+        auto _tt_thetime = _tt_stop-_tt_start;                                                                  \
         using std::chrono::duration_cast;                                                                       \
         using std::chrono::duration;                                                                            \
         if (_tt_thetime >= std::chrono::minutes(1))                                                             \
diff --git a/dlib/timing.h b/dlib/timing.h
index 2d5116ade4..27ca7aa8ae 100644
--- a/dlib/timing.h
+++ b/dlib/timing.h
@@ -89,8 +89,7 @@ namespace dlib
             // if this name buffer is empty then copy name into it
             if (buf[i][0] == '\0')
             {
-                using namespace std;
-                strncpy(buf[i], name, NAME_LENGTH-1);
+                std::strncpy(buf[i], name, NAME_LENGTH-1);
                 buf[i][NAME_LENGTH-1] = '\0';
             }
             // return the name buffer
@@ -99,8 +98,9 @@ namespace dlib
 
         inline uint64_t ts()
         {
-            using namespace std::chrono;
-            return duration_cast<duration<double,std::nano>>(high_resolution_clock::now().time_since_epoch()).count();
+            return std::chrono::duration_cast<std::chrono::duration<double, std::nano>>(
+                std::chrono::high_resolution_clock::now().time_since_epoch()
+            ).count();
         }
 
         inline void start(int i)
@@ -121,14 +121,13 @@ namespace dlib
 
         inline void print()
         {
-            using namespace std;
-            cout << "Timing report: " << endl;
+            std::cout << "Timing report: " << std::endl;
 
             // figure out how long the longest name is going to be.
             unsigned long max_name_length = 0;
             for (int i = 0; i < TIME_SLOTS; ++i)
             {
-                string name;
+                std::string name;
                 // Check if the name buffer is empty.  Use the name it contains if it isn't.
                 if (name_buf(i,"")[0] != '\0')
                     name = cast_to_string(i) + ": " + name_buf(i,"");
@@ -142,7 +141,7 @@ namespace dlib
                 if (time_buf()[i] != 0)
                 {
                     double time = time_buf()[i]/1000.0/1000.0;
-                    string name;
+                    std::string name;
                     // Check if the name buffer is empty.  Use the name it contains if it isn't.
                     if (name_buf(i,"")[0] != '\0')
                         name = cast_to_string(i) + ": " + name_buf(i,"");
@@ -151,16 +150,16 @@ namespace dlib
 
                     // make sure the name is always the same length.  Do so by padding with spaces
                     if (name.size() < max_name_length)
-                        name += string(max_name_length-name.size(),' ');
+                        name += std::string(max_name_length-name.size(),' ');
 
                     if (time < 1000)
-                        cout << "  " << name << ": " << time << " milliseconds" << endl;
+                        std::cout << "  " << name << ": " << time << " milliseconds" << std::endl;
                     else if (time < 1000*60)
-                        cout << "  " << name << ": " << time/1000.0 << " seconds" << endl;
+                        std::cout << "  " << name << ": " << time/1000.0 << " seconds" << std::endl;
                     else if (time < 1000*60*60)
-                        cout << "  " << name << ": " << time/1000.0/60.0 << " minutes" << endl;
+                        std::cout << "  " << name << ": " << time/1000.0/60.0 << " minutes" << std::endl;
                     else
-                        cout << "  " << name << ": " << time/1000.0/60.0/60.0 << " hours" << endl;
+                        std::cout << "  " << name << ": " << time/1000.0/60.0/60.0 << " hours" << std::endl;
                 }
             }
         }
diff --git a/dlib/tokenizer/tokenizer_kernel_c.h b/dlib/tokenizer/tokenizer_kernel_c.h
index f9604809d9..67abece181 100644
--- a/dlib/tokenizer/tokenizer_kernel_c.h
+++ b/dlib/tokenizer/tokenizer_kernel_c.h
@@ -61,16 +61,15 @@ namespace dlib
         const std::string& body
     ) 
     {
-        using namespace std;
         // make sure requires clause is not broken
-        DLIB_CASSERT( head.find_first_of(" \r\t\n0123456789") == string::npos &&
-                body.find_first_of(" \r\t\n") == string::npos ,
+        DLIB_CASSERT( head.find_first_of(" \r\t\n0123456789") == std::string::npos &&
+                body.find_first_of(" \r\t\n") == std::string::npos ,
             "\tvoid tokenizer::set_identifier_token()"
             << "\n\tyou can't define the IDENTIFIER token this way."
             << "\n\thead: " << head
             << "\n\tbody: " << body
             << "\n\tthis: " << this
-            );
+            )
 
         // call the real function
         tokenizer::set_identifier_token(head,body);


Test patch:
diff --git a/dlib/test/binary_search_tree.h b/dlib/test/binary_search_tree.h
index 18bdff70de..dec0cde7ee 100644
--- a/dlib/test/binary_search_tree.h
+++ b/dlib/test/binary_search_tree.h
@@ -18,7 +18,6 @@ namespace
 {
 
     using namespace test;
-    using namespace std;
     using namespace dlib;
 
     logger dlog("test.binary_search_tree");
@@ -173,9 +172,9 @@ namespace
 
             // serialize the state of test, then clear test, then
             // load the state back into test.
-            ostringstream sout;
+            std::ostringstream sout;
             serialize(test,sout);
-            istringstream sin(sout.str());
+            std::istringstream sin(sout.str());
             test.clear();
             deserialize(test,sin);
 
@@ -399,7 +398,7 @@ namespace
             for (int i = 0; i < 10000; ++i)
             {
                 a = ::rand()&0x7FFF;
-                m = max(a,m);
+                m = std::max(a,m);
                 test2.add(a,b);
             }
 
diff --git a/dlib/test/cmd_line_parser.h b/dlib/test/cmd_line_parser.h
index 6f8e411a48..f5c7090607 100644
--- a/dlib/test/cmd_line_parser.h
+++ b/dlib/test/cmd_line_parser.h
@@ -15,7 +15,6 @@ namespace
 {
     using namespace test;
     using namespace dlib;
-    using namespace std;
 
     logger dlog("test.cmd_line_parser");
 
diff --git a/dlib/test/conditioning_class.h b/dlib/test/conditioning_class.h
index 3c6c88b8dd..9fedc04696 100644
--- a/dlib/test/conditioning_class.h
+++ b/dlib/test/conditioning_class.h
@@ -4,7 +4,6 @@
 #define DLIB_TEST_CONDITIONING_CLASs_H_
 
 
-#include <sstream>
 #include <string>
 #include <ctime>
 #include <cstdlib>
@@ -17,7 +16,6 @@ namespace
 {
 
     using namespace test;
-    using namespace std;
     using namespace dlib;
 
     logger dlog("test.conditioning_class");
@@ -213,13 +211,13 @@ namespace
                         temp_total += test.get_count(a);
                     }
                     DLIB_TEST_MSG(temp_total == test.get_total(),
-                                 "temp_total == " << temp_total << endl <<
+                                 "temp_total == " << temp_total << std::endl <<
                                  "test.get_total() == " << test.get_total()
                     );
 
                     DLIB_TEST(test.get_count(alphabet_size-1) == counts[alphabet_size-1]);
                     DLIB_TEST_MSG(test.get_total() == total,
-                                 "test.get_total() == " << test.get_total() << endl <<
+                                 "test.get_total() == " << test.get_total() << std::endl <<
                                  "total == " << total
                     );
 
@@ -311,15 +309,15 @@ namespace
                         test.get_symbol(k,symbol,low_count,high_count);
                         DLIB_TEST(high_count - low_count == test.get_count(symbol));
                         DLIB_TEST_MSG(j == symbol,
-                                     "j == " << j << endl <<
-                                     "k == " << k << endl <<
-                                     "symbol == " << symbol << endl <<
-                                     "low_counts[j] == " << low_counts[j] << endl <<
-                                     "high_counts[j] == " << high_counts[j] << endl <<
-                                     "low_counts[symbol] == " << low_counts[symbol] << endl <<
-                                     "high_counts[symbol] == " << high_counts[symbol] << endl << 
-                                     "low_count == " << low_count << endl << 
-                                     "high_count == " << high_count << endl << 
+                                     "j == " << j << std::endl <<
+                                     "k == " << k << std::endl <<
+                                     "symbol == " << symbol << std::endl <<
+                                     "low_counts[j] == " << low_counts[j] << std::endl <<
+                                     "high_counts[j] == " << high_counts[j] << std::endl <<
+                                     "low_counts[symbol] == " << low_counts[symbol] << std::endl <<
+                                     "high_counts[symbol] == " << high_counts[symbol] << std::endl << 
+                                     "low_count == " << low_count << std::endl << 
+                                     "high_count == " << high_count << std::endl << 
                                      "temp.count(j) == " << test.get_count(j)
                         );
                         DLIB_TEST_MSG(low_count == low_counts[j],
@@ -618,13 +616,13 @@ namespace
                     if (!oom)
                     {
                         DLIB_TEST_MSG(temp_total == test.get_total(),
-                                     "temp_total == " << temp_total << endl <<
+                                     "temp_total == " << temp_total << std::endl <<
                                      "test.get_total() == " << test.get_total()
                         );
 
                         DLIB_TEST(test.get_count(alphabet_size-1) == counts[alphabet_size-1]);
                         DLIB_TEST_MSG(test.get_total() == total,
-                                     "test.get_total() == " << test.get_total() << endl <<
+                                     "test.get_total() == " << test.get_total() << std::endl <<
                                      "total == " << total
                         );
                     }
@@ -726,15 +724,15 @@ namespace
                             test.get_symbol(k,symbol,low_count,high_count);
                             DLIB_TEST(high_count - low_count == test.get_count(symbol));
                             DLIB_TEST_MSG(j == symbol,
-                                         "j == " << j << endl <<
-                                         "k == " << k << endl <<
-                                         "symbol == " << symbol << endl <<
-                                         "low_counts[j] == " << low_counts[j] << endl <<
-                                         "high_counts[j] == " << high_counts[j] << endl <<
-                                         "low_counts[symbol] == " << low_counts[symbol] << endl <<
-                                         "high_counts[symbol] == " << high_counts[symbol] << endl << 
-                                         "low_count == " << low_count << endl << 
-                                         "high_count == " << high_count << endl << 
+                                         "j == " << j << std::endl <<
+                                         "k == " << k << std::endl <<
+                                         "symbol == " << symbol << std::endl <<
+                                         "low_counts[j] == " << low_counts[j] << std::endl <<
+                                         "high_counts[j] == " << high_counts[j] << std::endl <<
+                                         "low_counts[symbol] == " << low_counts[symbol] << std::endl <<
+                                         "high_counts[symbol] == " << high_counts[symbol] << std::endl << 
+                                         "low_count == " << low_count << std::endl << 
+                                         "high_count == " << high_count << std::endl << 
                                          "temp.count(j) == " << test.get_count(j)
                             );
                             DLIB_TEST_MSG(low_count == low_counts[j],