c++ - limited value in a File output -
i have program returns execution time , output of each run diplayed in file in same row .
#include <iostream> #include <fstream> #include <math> #include <boost> using namespace std; int main() { std::ofstream file("myfile.txt",std::ios_base::app); v2 = rand() % 100 + 1; // burn time std::cout << v2 ; // burn time boost::chrono::duration<double> sec = boost::chrono::system_clock::now() - start; file<<sec.count() << ";"; file.close(); return 0 ; }
after 4 run here output in file :
0.0190567;4.92035;11.0541;13.1457;
i after 30 runs 30'th result must displayed in newline . without added functions or loops affect duration of runtime .i think there other way format output file via awk sed .
you can use awk.
awk '{ gsub(/([0-9]+(.[0-9]*)?;){30}/, "&\n"); print }' myfile.txt
this should insert \n
after each 30th ;
Comments
Post a Comment