diff --git a/Box_intersection_d/test/Box_intersection_d/automated_test.cpp b/Box_intersection_d/test/Box_intersection_d/automated_test.cpp index 52d06a1f141..48a2c37f2c3 100644 --- a/Box_intersection_d/test/Box_intersection_d/automated_test.cpp +++ b/Box_intersection_d/test/Box_intersection_d/automated_test.cpp @@ -23,6 +23,14 @@ // enable invariant checking #define CGAL_SEGMENT_TREE_CHECK_INVARIANTS 1 +#ifndef _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif + +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS 1 +#endif + #include #include #include diff --git a/Box_intersection_d/test/Box_intersection_d/util.h b/Box_intersection_d/test/Box_intersection_d/util.h index 23b8213bbea..59bedccf6a7 100644 --- a/Box_intersection_d/test/Box_intersection_d/util.h +++ b/Box_intersection_d/test/Box_intersection_d/util.h @@ -2,14 +2,6 @@ #define CGAL_BOX_INTERSECTION_D_UTIL_H -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE 1 -#endif - -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS 1 -#endif - #include #include // for pair #include diff --git a/Minkowski_sum_2/test/Minkowski_sum_2/test_exact_offset.cpp b/Minkowski_sum_2/test/Minkowski_sum_2/test_exact_offset.cpp index 45843652f51..1fda8219ff4 100644 --- a/Minkowski_sum_2/test/Minkowski_sum_2/test_exact_offset.cpp +++ b/Minkowski_sum_2/test/Minkowski_sum_2/test_exact_offset.cpp @@ -3,6 +3,7 @@ #ifndef CGAL_USE_CORE #include +#include int main () { @@ -24,15 +25,6 @@ int main () #include -#ifndef _CRT_SECURE_NO_DEPRECATE -#define _CRT_SECURE_NO_DEPRECATE 1 -#endif - -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS 1 -#endif - - typedef CGAL::CORE_algebraic_number_traits Nt_traits; typedef Nt_traits::Rational Rational; typedef Nt_traits::Algebraic Algebraic; @@ -91,8 +83,10 @@ int main (int argc, char **argv) // Read the offset radius. int numer, denom; - - if (sscanf (argv[i+1], "%d/%d", &numer, &denom) != 2) + char c; + std::istringstream iss(argv[i+1]); + iss >> numer >> c >> denom; + if (! iss.good()) { std::cerr << "Invalid radius: " << argv[i+1] << std::endl; return (1); diff --git a/Nef_3/test/Nef_3/include/CGAL/test_Nef_3.h b/Nef_3/test/Nef_3/include/CGAL/test_Nef_3.h index e4ff83ebba9..73db70ceb94 100644 --- a/Nef_3/test/Nef_3/include/CGAL/test_Nef_3.h +++ b/Nef_3/test/Nef_3/include/CGAL/test_Nef_3.h @@ -34,6 +34,7 @@ #include #include #include +#include namespace CGAL { @@ -143,13 +144,10 @@ private: } bool does_nef3_equals_file(Nef_polyhedron& N, const char* name) { - char* fullname = new char[std::strlen(datadir)+std::strlen(name)+1]; - std::strcpy(fullname, datadir); - std::strcat(fullname, name); + std::string fullname = std::string(datadir) + std::string(name); std::ofstream out("data/temp.nef3"); out << N; - bool b = are_files_equal("data/temp.nef3",fullname); - delete [] fullname; + bool b = are_files_equal("data/temp.nef3",fullname.c_str()); return b; } @@ -163,14 +161,11 @@ private: } Nef_polyhedron load_nef3(const char* name) { - char* fullname = new char[std::strlen(datadir)+std::strlen(name)+1]; - std::strcpy(fullname, datadir); - std::strcat(fullname, name); - std::ifstream input(fullname); + std::string fullname = std::string(datadir) + std::string(name); + std::ifstream input(fullname.c_str()); assert(input.good()); Nef_polyhedron tmp; input >> tmp; - delete[] fullname; return tmp; } diff --git a/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h b/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h index 3f5c5e365e5..d0313eeecf7 100644 --- a/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h +++ b/Straight_skeleton_2/include/CGAL/IO/Dxf_writer.h @@ -27,8 +27,10 @@ #include #include #include +#include #include #include +#include namespace CGAL { @@ -140,24 +142,24 @@ private: std::string get_entity_handle() { - char lBuff[64]; - sprintf(lBuff,"%5x",mHandle++); - return std::string(lBuff); + std::ostringstream oss; + oss << boost::format("%5x") % mHandle++; + return oss.str(); } std::string to_str ( int aN ) { - char lBuff[64]; - sprintf(lBuff,"%6d",aN); - return std::string(lBuff); + std::ostringstream oss; + oss << boost::format("%6d") % aN; + return oss.str(); } std::string to_str ( double aN ) { - char lBuff[64]; - sprintf(lBuff,"%6.6f",aN); - return std::string(lBuff); + std::ostringstream oss; + oss << boost::format("%6.6f") % aN; + return oss.str(); } void insert_line ( Line_iterator aPos, std::string aLine ) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO.h b/Surface_mesh/include/CGAL/Surface_mesh/IO.h index bcfc15dca9a..2f16c770120 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO.h @@ -29,7 +29,8 @@ //== INCLUDES ================================================================= #include -#include +#include +#include #include #include #include @@ -51,17 +52,14 @@ namespace CGAL { namespace internal { // helper function -template void read(FILE* in, T& t) + template void read(std::istream& in, T& t) { - std::size_t err = 0; - err = fread(&t, 1, sizeof(t), in); - if(err != 0) - throw std::runtime_error("fread error"); + in.read(reinterpret_cast(&t), sizeof(t)); } template bool read_off_binary(Surface_mesh& mesh, - FILE* in, + std::istream& in, const bool has_normals, const bool has_texcoords) { @@ -95,7 +93,7 @@ bool read_off_binary(Surface_mesh& mesh, // read vertices: pos [normal] [color] [texcoord] - for (i=0; i& mesh, template bool read_off_ascii(Surface_mesh& mesh, - FILE* in, + std::istream& in, const bool has_normals, const bool has_texcoords) { @@ -150,9 +148,8 @@ bool read_off_ascii(Surface_mesh& mesh, typedef typename K::Vector_3 Texture_coordinate; boost::array buffer; - char line[100], *lp; - unsigned int i, j, items, idx; - int nc; + std::string line; + unsigned int i, j, idx; unsigned int nV, nF, nE; typename Mesh::Vertex_index v; @@ -163,28 +160,29 @@ bool read_off_ascii(Surface_mesh& mesh, if (has_normals) normals = mesh.template add_property_map("v:normal").first; if (has_texcoords) texcoords = mesh.template add_property_map("v:texcoord").first; - int c; + char c; do { - c = getc(in); + c = in.get(); if(c == '#'){ - fgets(line, 100, in); + getline(in,line); } else { - ungetc(c,in); + in.putback(c); break; } }while(1); // #Vertice, #Faces, #Edges - items = fscanf(in, "%d %d %d\n", (int*)&nV, (int*)&nF, (int*)&nE); + in >> nV >> nF >> nE; + getline(in,line); // reads eol mesh.clear(); mesh.reserve(nV, (std::max)(3*nV, nE), nF); // read vertices: pos [normal] [color] [texcoord] - for (i=0; i& mesh, } // position - items = sscanf(lp, "%lf %lf %lf%n", &(buffer[0]), &buffer[1], &buffer[2], &nc); - CGAL_assertion(items==3); + std::istringstream iss(line); + iss >> iformat(buffer[0]) >> iformat(buffer[1]) >> iformat(buffer[2]); v = mesh.add_vertex(Point_3(buffer[0], buffer[1], buffer[2])); - lp += nc; // normal if (has_normals) { - if (sscanf(lp, "%lf %lf %lf%n", &buffer[0], &buffer[1], &buffer[2], &nc) == 3) - { - normals[v] = Vector_3(buffer[0], buffer[1], buffer[2]); - } - lp += nc; + iss >> iformat(buffer[0]) >> iformat(buffer[1]) >> iformat(buffer[2]); } // tex coord if (has_texcoords) { - items = sscanf(lp, "%lf %lf%n", &buffer[0], &buffer[1], &nc); - CGAL_assertion(items == 2); + iss >> iformat(buffer[0]) >> iformat(buffer[1]); texcoords[v] = Vector_3(buffer[0], buffer[1], 0.0); - lp += nc; } } @@ -222,7 +213,7 @@ bool read_off_ascii(Surface_mesh& mesh, for (i=0; i& mesh, } // #vertices - items = sscanf(lp, "%d%n", (int*)&nV, &nc); - CGAL_assertion(items == 1); + std::istringstream iss(line); + iss >> nV; vertices.resize(nV); - lp += nc; // indices for (j=0; j> idx; vertices[j] = typename Mesh::Vertex_index(idx); - lp += nc; } if(!mesh.add_face(vertices).is_valid()) { @@ -249,7 +237,6 @@ bool read_off_ascii(Surface_mesh& mesh, return false; } } - CGAL_USE(items); return true; } } @@ -279,7 +266,7 @@ bool read_off_ascii(Surface_mesh& mesh, template bool read_off(Surface_mesh& mesh, const std::string& filename) { - char line[100]; + std::string line; bool has_texcoords = false; bool has_normals = false; bool has_hcoords = false; @@ -287,25 +274,24 @@ bool read_off(Surface_mesh& mesh, const std::string& filename) bool is_binary = false; // open file (in ASCII mode) - FILE* in = std::fopen(filename.c_str(), "r"); + std::ifstream in(filename.c_str()); if (!in) return false; // read header: [ST][C][N][4][n]OFF BINARY - char *c = std::fgets(line, 100, in); - CGAL_assertion(c != NULL); - c = line; + std::getline(in,line); + const char *c = line.c_str(); if (c[0] == 'S' && c[1] == 'T') { has_texcoords = true; c += 2; } if (c[0] == 'N') { has_normals = true; ++c; } if (c[0] == '4') { has_hcoords = true; ++c; } if (c[0] == 'n') { has_dim = true; ++c; } - if (strncmp(c, "OFF", 3) != 0) { std::fclose(in); return false; } // no OFF + if (strncmp(c, "OFF", 3) != 0) { in.close(); return false; } // no OFF if (strncmp(c+4, "BINARY", 6) == 0) is_binary = true; // homogeneous coords, and vertex dimension != 3 are not supported if (has_hcoords || has_dim) { - std::fclose(in); + in.close(); return false; } @@ -313,10 +299,9 @@ bool read_off(Surface_mesh& mesh, const std::string& filename) // if binary: reopen file in binary mode if (is_binary) { - std::fclose(in); - in = std::fopen(filename.c_str(), "rb"); - c = std::fgets(line, 100, in); - CGAL_assertion(c != NULL); + in.close(); + in.open(filename.c_str(), std::ios::binary); + std::getline(in,line); } // read as ASCII or binary @@ -324,8 +309,7 @@ bool read_off(Surface_mesh& mesh, const std::string& filename) internal::read_off_binary(mesh, in, has_normals, has_texcoords) : internal::read_off_ascii(mesh, in, has_normals, has_texcoords)); - - std::fclose(in); + in.close(); return ok; } diff --git a/Triangulation_3/test/Triangulation_3/test_regular_remove_3.cpp b/Triangulation_3/test/Triangulation_3/test_regular_remove_3.cpp index ca6c3757cb1..06ef052c5eb 100644 --- a/Triangulation_3/test/Triangulation_3/test_regular_remove_3.cpp +++ b/Triangulation_3/test/Triangulation_3/test_regular_remove_3.cpp @@ -343,10 +343,10 @@ int main(int argc, char **argv) boost::int32_t seed0 = 42, seed1 = 43, seed2 = 42, seed3 = 42; // You can also pass seeds on the command line. - if (argc > 1) std::sscanf (argv[1], "%d", &seed0); - if (argc > 2) std::sscanf (argv[2], "%d", &seed1); - if (argc > 3) std::sscanf (argv[3], "%d", &seed2); - if (argc > 4) std::sscanf (argv[4], "%d", &seed3); + if (argc > 1) { std::istringstream iss(argv[1]); iss >>seed0; } + if (argc > 2) { std::istringstream iss(argv[2]); iss >>seed1; } + if (argc > 3) { std::istringstream iss(argv[3]); iss >>seed2; } + if (argc > 4) { std::istringstream iss(argv[4]); iss >>seed3; } Cls T; point_set points;