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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -