error with std::ostringsteam and std::string
- by pyCthon
Hi i want to save many different csv files from a function with a naming convention based on a different double value. I do this with a for loop and pass a string value to save each .csv file differently. Below is an example of what I'm trying to do the desired result would be
1.1_file.csv
1.2_file.csv
but instead i get
1.1_file.csv
1.11.2_file.csv
Here is a working sample code, what can i do to fix this
#include <sstream>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <vector>
int main(){
std::string file = "_file.csv";
std::string s;
std::ostringstream os;
double x;
for(int i = 0; i < 10; i++){
x = 0.1 + 0.1 *i;
os << std::fixed << std::setprecision(1);
os << x;
s = os.str();
std::cout<<s+file<<std::endl;
s.clear();
}
return 0;
}