Handling strings with std::string
authorklao
Wed, 15 Sep 2004 14:25:44 +0000
changeset 858acc83957ee4a
parent 857 4e948fd205f7
child 859 2570784896d8
Handling strings with std::string
Do not segfault if srcdir env. variable is not set.
src/test/preflow_test.cc
     1.1 --- a/src/test/preflow_test.cc	Wed Sep 15 14:04:57 2004 +0000
     1.2 +++ b/src/test/preflow_test.cc	Wed Sep 15 14:25:44 2004 +0000
     1.3 @@ -1,4 +1,6 @@
     1.4  #include <fstream>
     1.5 +#include <string>
     1.6 +
     1.7  #include "test_tools.h"
     1.8  #include <hugo/smart_graph.h>
     1.9  #include <hugo/dimacs.h>
    1.10 @@ -6,8 +8,6 @@
    1.11  #include <hugo/skeletons/graph.h>
    1.12  #include <hugo/skeletons/maps.h>
    1.13  
    1.14 -#include <string.h>
    1.15 -
    1.16  using namespace hugo;
    1.17  
    1.18  void check_Preflow() 
    1.19 @@ -69,17 +69,17 @@
    1.20  
    1.21    typedef Preflow<Graph, int> PType;
    1.22  
    1.23 -  char *f_name;
    1.24 +  string f_name;
    1.25 +  if( getenv("srcdir") ) {
    1.26 +    f_name = string(getenv("srcdir")) + "/preflow_graph.inp";
    1.27 +  }
    1.28 +  else {
    1.29 +    f_name = "preflow_graph.inp";
    1.30 +  }
    1.31    
    1.32 -  f_name=new char[strlen(getenv("srcdir"))+50];
    1.33 -  strcpy(f_name,getenv("srcdir"));
    1.34 -  strcat(f_name,"/preflow_graph.inp");
    1.35 +  std::ifstream file(f_name.c_str());
    1.36    
    1.37 -  std::ifstream file(f_name);
    1.38 -  
    1.39 -  check(file,"Input file '" << f_name << "' not found.");
    1.40 -  
    1.41 -  delete [] f_name;
    1.42 +  check(file, "Input file '" << f_name << "' not found.");
    1.43    
    1.44    Graph G;
    1.45    Node s, t;
    1.46 @@ -180,6 +180,3 @@
    1.47  	min_min_cut_value == max_min_cut_value,
    1.48  	"The max flow value or the three min cut values are incorrect.");
    1.49  }
    1.50 -
    1.51 -
    1.52 -