Jain
Jain

Reputation: 999

Inserting values in csv through c++

I have written two lines of code to insert my output values in csv, but couldn't find values in excel except the first column which has some vague values.

MyExcelFile << "N, Bal, Int,P" << endl;
for (int i = 1; i <= period; i++)
{
    MyExcelFile << i << int(balance[i - 1]) << int(interest[i - 1]) << int(payment[i - 1]) << int(sprincipal[i - 1]) << endl;

}

I get the first row as N Bal Int P , that comes from first statement outside loop. But second row I Just get 1 that is A2 if you open in excel which is not value of i that is should be and rest all the cells are blank. Can anyone help on where am I making a mistake. Thanks in advance.

Upvotes: 0

Views: 139

Answers (1)

OshoParth
OshoParth

Reputation: 1552

The First line works fine as you provide the proper separators denoting the different cells but when moving inside the loot the resultant command for the statements specified becomes a single sting with no separators thus following code might be helpful.

MyExcelFile << "N, Bal, Int,P" << endl;
for (int i = 1; i <= period; i++)
{
    MyExcelFile << i <<"," << int(balance[i - 1]) <<"," << int(interest[i - 1]) <<"," << int(payment[i - 1]) <<"," << int(sprincipal[i - 1]) << endl;
}

Upvotes: 1

Related Questions