0

I am trying to write in a tabular form in .csv file. many string variables (freq voltage current S11 S22 S21 S12) contains big data.
for exp,

... and so on ...

first I converted all variables data row into column by replacing "," to "\n", for writing in vertical form. for exp,

convert to

string voltage , freq, curt;
freq= tmp.query("*FMA?\n");
voltage = tmp.query("*VOL?\n");
curt=   tmp.query("*CURR?\n");
replace(begin(freq), end(freq), ',', '\n');
replace(begin(voltage ), end(voltage), ',', '\n');
replace(begin(curt), end(curt), ',', '\n');
filewrite << freq<< voltage <<curt; 

Jubin Justifies
  • 323
  • 2
  • 11

1 Answers1

0

Its done. Split by "," and use token to write in tabular form.

ofstream filewrite;
filewrite.open("............");
string voltage , freq;
freq= "A1, A2, A3";
voltage = "B1, B2, B3";

string delimiter = ",";
    size_t pos = 0;
    string token, token2;
    while ((pos = freq.find(delimiter)) != string::npos && (pos =voltage .find(delimiter)) != string::npos)
    {
        token = freq.substr(0, pos);
        token2 = voltage .substr(0, pos);
        filewrite << token << "," << token2 << endl;
        freq.erase(0, pos + delimiter.length());
        str2.erase(0, pos + delimiter.length());
    }

    filewrite << freq<<"," << voltage ;
filewrite.close();

}