Question: I have a MYSQL table in which I want to perform following operation.

```

ID     Com      Com_Sub Year    Parameter       Value
6       A       A1     2010     Profit      33766.18
20      A       A1     2010     Revenues    2793617.12
30      A       A1     2011     Profit      84310.73
54      A       A1     2009     Profit      129129.5284
60      A       A1     2011     Revenues    2049157.294
70      B       B1     2010     Profit      3753765490
76      B       B1     2010     Revenues    217326.7561

```

Now I need to manipulate it and make it like this

```

ID     Com      Com_Sub Year    Parameter       Value          New Value
6       A        A1     2010    Profit         33766.18       0.0123
20      A        A1     2010    Revenues       2793617.12
30      A        A1     2011    Profit         84310.73       0.0252
54      A        A1     2009    Profit         129129.5284    
60      A        A1     2011    Revenues       2049157.294
70      B        B1     2010    Profit         3753765490     1.235
76      B        B1     2010    Revenues       217326.7561

```

this means whenever I have common Year and Common Com\_sub value in the row I need to add the division of both the values.

Answer: 
I think I'd do something more like this:

```
{    
    std::cout << "Please enter output file name: ";

    std::string outputFileName;       
    std::getline(outputFileName, std::cin);

    std::ofstream outputFile(outputFileName.c_str());
    outputFile.write((static_cast<char *>(&c1), len);
} // file closes automatically when it goes out of scope.

```
I fixed it getting rid of out and writing c1 directly to the file. 

```
ofstream outFile;
char outputFileName[256];
cout << "Enter output file name: ";
cin >> outputFileName;
cout << endl; outFile.open(outputFileName,ios::trunc);
for(int i=0; i<len-1; i++){ //-1 b/c added \n at the end. 
    outFile = c1[i];
} 
outFile.close();

```