So I have some numerical code which writes a time step as the file name. I need to use quite small time steps and for some reason I can't get the code to write the float value to my file name. Here's a MWE
#include <iostream>
#include <fstream>
#include <random>
#include <chrono>
#include "nsoliton.hpp"
int main()
{
float step = 2/10; // MAKE A DECIMAL
int tmax = 100.;
std::cout.precision(4);
std::cout << "step =" << std::setw(step) << std::endl;
std::fstream file3(std::to_string(step) + "_t1.txt", std::ios::out);
return 0;
}
// g++ -c -O2 -std=c++11 -fopenmp floatMWE.cpp; g++ -fopenmp -O2 -o floatMWE floatMWE.o -lmpfr -lgmp; ./floatMWE
The goal should be to have sequential files labelled e.g.,
0_t1.txt, 1_t1.txt ...
but obviously accounting for the step so non-integer
any clues?
I tried using ``setw'' but that still doesn't work. Checked also using a print command and it too won't print the float value. I also tried changing `'step'' from a float to an int but still nothing.