lundi 6 juillet 2020

C++, Writing data in columns [closed]

I would like to write data to a CSV file every time in each row and thos row should have 5 columns. I have data from 5 variables. I want to write all 5 variables side by side (columns wise) in a CSV file. Each time these 5 variables write to a new row. I found that ctime() will print a new line at the end of the string. Which time function is suitable for my requirement?

std::ofstream myfile;
myfile.open("sample.csv",std::ios_base::app);
myfile << ctime(&my_time)<< ","
       << ctime(&my_time1)<< ","
       << ctime(&my_time2)<< ","
       << data<< ","
       << feedback
       << "\n";

I tried this way. And the output is.

time 
      time1
      time2
      data
            feedback

However I want the output be like:

time time1 time2 data feedback
time time1 time2 data feedback

Aucun commentaire:

Enregistrer un commentaire