Click here to Skip to main content
15,349,321 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
This function saves the new file----------------------------------------
void savefile(struct datavalues d)
    string newfilename;
    cout << "Enter the new file name with proper extension"<< endl;
    cin >> newfilename; 
    ofstream file(newfilename);
    for(int i=0;i<d.totalcol;i++)
    for(int i=0;i<d.totalrow;i++)
        for(int j=0;j<d.totalcol;j++)
            file<<d.fulldata[i][j]<<" ";
    string str="Created and saved a newfile as "+newfilename+"\n";

What I have tried:

I said that it is used to make a new file with proper extension
Updated 26-Nov-21 22:36pm
Patrice T 26-Nov-21 18:00pm
What is the question ?
Greg Utas 26-Nov-21 18:45pm
It sounds like he wants an explanation of what the code does.
Omar ice killerjj 26-Nov-21 21:04pm
i want only comments for the code
Omar ice killerjj 26-Nov-21 21:16pm
i know what it does
Richard MacCutchan 27-Nov-21 4:55am
Then you should be able to write the comments.
Omar ice killerjj 26-Nov-21 21:16pm
I want to know how to writes comments for it
phil.o 27-Nov-21 1:58am

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();

Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?
the code is about saving the in parameter string with some UI to ask for the file name and than writes explicitly the struct.

I dont like that the struct is written in some function but would prefer some class with struct data and a save function.

To better understand the code lines you need to understand File I/O in C++.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900