From ae5546a3eda379002a468c4b9eb43f48e3ea80cd Mon Sep 17 00:00:00 2001 From: Christian Reiling Date: Tue, 27 Nov 2018 11:11:19 +0100 Subject: [PATCH] Using stringstream and bugfixing using c_str(). Compatible with kalinka now --- src/mc_electron/constants.h | 1 + src/mc_electron/simulation.cpp | 18 ++++++++++-------- src/mc_electron/tests.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/mc_electron/constants.h b/src/mc_electron/constants.h index 96b62d3..c2138ae 100644 --- a/src/mc_electron/constants.h +++ b/src/mc_electron/constants.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/src/mc_electron/simulation.cpp b/src/mc_electron/simulation.cpp index fbd318e..2d78f67 100644 --- a/src/mc_electron/simulation.cpp +++ b/src/mc_electron/simulation.cpp @@ -223,32 +223,34 @@ void Simulation::initLogger(void) { for (int i = 0; i < numberZBins; i++) { - string fileName = dirname + "/z=" + to_string(zLogValues[i]) + ".dat"; - outStream[i].open(fileName); + stringstream fileName; + fileName << dirname << "/z=" << zLogValues[i] << ".dat"; + outStream[i].open(fileName.str().c_str()); } } string Simulation::getDirName() { string poub = getenv("poub"); string pname = getenv("pname"); int i = 1; - string dirname; + stringstream dirname; struct stat statbuf; int isDir; do { - dirname = poub + "/" + pname + "_" + getTimeString() + "_" + to_string(i++); + dirname.clear(); + dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++; isDir = 0; - if (stat(dirname.c_str(), &statbuf) != -1) { + if (stat(dirname.str().c_str(), &statbuf) != -1) { if (S_ISDIR(statbuf.st_mode)) { isDir = 1; } } } while ( isDir == 1 ); - if (mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { - cerr<<"Simulation::initLogger: Could not create folder "<