diff --git a/src/library.cpp b/src/library.cpp index d815afdbb5..7840567866 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -137,7 +137,7 @@ void lammps_open(int argc, char **argv, MPI_Comm communicator, void **ptr) *ptr = (void *) lmp; } catch(LAMMPSException & e) { - fprintf(stderr, "LAMMPS Exception: %s", e.message.c_str()); + fmt::print(stderr, "LAMMPS Exception: {}", e.message); *ptr = (void *) NULL; } #else @@ -172,7 +172,7 @@ void lammps_open_no_mpi(int argc, char **argv, void **ptr) *ptr = (void *) lmp; } catch(LAMMPSException & e) { - fprintf(stderr, "LAMMPS Exception: %s", e.message.c_str()); + fmt::print(stderr, "LAMMPS Exception: {}", e.message); *ptr = (void*) NULL; } #else diff --git a/src/utils.cpp b/src/utils.cpp index cac94fe0cf..b223710cab 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -155,7 +155,7 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size, errmsg += filename; errmsg += "'"; - if (error) error->one(srcname,srcline,errmsg.c_str()); + if (error) error->one(srcname,srcline,errmsg); if (s) *s = '\0'; // truncate string to empty in case error is NULL } return; @@ -184,7 +184,7 @@ void utils::sfread(const char *srcname, int srcline, void *s, size_t size, errmsg += filename; errmsg += "'"; - if (error) error->one(srcname,srcline,errmsg.c_str()); + if (error) error->one(srcname,srcline,errmsg); } return; } @@ -238,9 +238,9 @@ double utils::numeric(const char *file, int line, const char *str, msg += str; msg += "' in input script or data file"; if (do_abort) - lmp->error->one(file,line,msg.c_str()); + lmp->error->one(file,line,msg); else - lmp->error->all(file,line,msg.c_str()); + lmp->error->all(file,line,msg); } return atof(str); @@ -273,9 +273,9 @@ int utils::inumeric(const char *file, int line, const char *str, msg += str; msg += "' in input script or data file"; if (do_abort) - lmp->error->one(file,line,msg.c_str()); + lmp->error->one(file,line,msg); else - lmp->error->all(file,line,msg.c_str()); + lmp->error->all(file,line,msg); } return atoi(str); @@ -308,9 +308,9 @@ bigint utils::bnumeric(const char *file, int line, const char *str, msg += str; msg += "' in input script or data file"; if (do_abort) - lmp->error->one(file,line,msg.c_str()); + lmp->error->one(file,line,msg); else - lmp->error->all(file,line,msg.c_str()); + lmp->error->all(file,line,msg); } return ATOBIGINT(str); @@ -343,9 +343,9 @@ tagint utils::tnumeric(const char *file, int line, const char *str, msg += str; msg += "' in input script or data file"; if (do_abort) - lmp->error->one(file,line,msg.c_str()); + lmp->error->one(file,line,msg); else - lmp->error->all(file,line,msg.c_str()); + lmp->error->all(file,line,msg); } return ATOTAGINT(str); diff --git a/src/write_data.cpp b/src/write_data.cpp index 677b619ada..5d67d4471c 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -123,7 +123,7 @@ void WriteData::command(int narg, char **arg) if (domain->triclinic) domain->lamda2x(atom->nlocal+atom->nghost); } - write(file.c_str()); + write(file); } /* ---------------------------------------------------------------------- @@ -131,7 +131,7 @@ void WriteData::command(int narg, char **arg) might later let it be directly called within run/minimize loop ------------------------------------------------------------------------- */ -void WriteData::write(const char *file) +void WriteData::write(const std::string &file) { // special case where reneighboring is not done in integrator // on timestep data file is written (due to build_once being set) @@ -187,7 +187,7 @@ void WriteData::write(const char *file) // open data file if (me == 0) { - fp = fopen(file,"w"); + fp = fopen(file.c_str(),"w"); if (fp == NULL) error->one(FLERR,fmt::format("Cannot open data file {}: {}", file, utils::getsyserror())); diff --git a/src/write_data.h b/src/write_data.h index 5055a25d98..5863b68292 100644 --- a/src/write_data.h +++ b/src/write_data.h @@ -21,6 +21,7 @@ CommandStyle(write_data,WriteData) #define LMP_WRITE_DATA_H #include "pointers.h" +#include namespace LAMMPS_NS { @@ -28,7 +29,7 @@ class WriteData : protected Pointers { public: WriteData(class LAMMPS *); void command(int, char **); - void write(const char *); + void write(const std::string &); private: int me,nprocs; diff --git a/src/write_restart.cpp b/src/write_restart.cpp index 1469e6b3e4..3c793e5f6a 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -293,9 +293,6 @@ void WriteRestart::write(std::string file) std::string multiname = file; multiname.replace(multiname.find("%"),1,fmt::format("{}",icluster)); - fp = fopen(multiname.c_str(),"wb"); - if (fp == NULL) - error->one(FLERR,fmt::format("Cannot open restart file {}",multiname).c_str()); if (filewriter) { fp = fopen(multiname.c_str(),"wb");