my program sends data to a certain file but the program creates data for 2500 times and each time the previous number is erased and new number is saved to file. but I want all the numbers to be saved to the text file
Hi!
you can solve the problem by using APPEND function because without using this function file is over write by program and cannot save previous data.
use
app();
you should check function name. hopefully it will help you.
ENJOY!!!
opening it with ios:: append solved the problem but still i have another one
I'm sending the code below you dont have to go through all the code but the problem is I want this function to turn for 2500 times but when I put a for loop after defining vector dataholder and floats program doesn't work. it breaks although it works perfectly without for loop:((
<
I want this function to turn for 2500 times but when I put a for loop after defining vector dataholder and floats program doesn't work. it breaks although it works perfectly without for loop
I'm sorry for not being precise I2M gonna get used with these terms. What I meant is that the main part begins(bcoz code above is the class function implementation ) it takes the data but it never ends. "press any key ..." never shows up. Another detail: I changed the above code to turn sum/z instead of saving it to a file
First: What do you mean when you say "turn"? That makes no sense at all.
Second: Think about the steps you go through to write to a file. Try to write the code so that you have all the data of your file in your vector. Now, imagine each 'cell' of the vector as a line in that file. That is how your file will look like. Now, use a for loop. Start at 0, and end with whatever_your_vector_is_named.size(). This will loop from 0- the end of your vector. EX:
1 2 3 4
for(unsignedint x = 0; x < myvect.size(); x++)
{
continue;
}
Now, if you want to go even further, you can add an 'if' statement to make sure you do not add an empty line to the end of your file:
1 2 3 4 5 6 7 8 9 10
out.open(file.c_str(), ios::app);
for(unsignedint x = 0; x < vector.size(); x++)
{
out<< text;
if(x < (myvect.size() - 1)) //if it is less than the last write-able 'cell'
{
out<< endl;
}
}
out.close();
That will write each part of the vector on a new line except for the last line. So that there are no lines in the file that do not contain nothing, unless your vector conatined nothing.