I have the following vector that represents my time iterations in the code that I would like to print in a text file for documentation/debugging purposes.
1 2 3 4 5 6 7 8 9
//initialize the vector to zeros
std::vector<double> time(iter_max + 1,0.0);
// Update time
time[iter + 1] = time[iter] + dt;
// print in the terminal:
//output time stamp
printf("Iteration = %d t = %.10f phi_iter = %d\n", iter, time[iter+1], phi_iter);
...
I wrote this function to write out my time stamp into a text file, but I am having the error: "operand types are incompatible ("int" and "int *")"
1 2 3 4 5 6 7 8 9 10 11 12 13
void print1DArrf(char filename[], double arr[], int nArr[]){
FILE *fptr;
fptr = fopen(filename, "w");
// Get size of the 1D array first.
for (int i = 0; i < nArr; i++) { //ERROR
fprintf(fptr,"%+4.16le\n",arr[i]);
}
fclose(fptr);
}
Above that line, you have a comment saying to get the size of the 1D array first. I presume this step was accidentally skipped. Friendly warning, though, I wouldn't try to use sizeof in this context.
@Furry Guy
I see, but it's a bit complicated. I am sort of benchmarking this C++ code to another version in MATLAB and I kinda want the times to be similar for me to compare some results.