c++ - Access Violation Reading Location using open file stream -


i know question has been asked lots of times. but, in case, error not present think might different. using c++, visual studio 2013, windows 7 x64.

here's relevant code:

void writedatatofile(const char *fname, string title, const vecdoub& spec_x, const vecdoub& spec_y, const vecdoub& freq) {     ofstream of;     of.open(fname, ios_base::out);     if (!of.is_open())     {         return;     }     of << "somename" << endl;     of << "waves/s" << "\t" << title << endl;     of << "begin" << endl;     (int i=0; i<spec_x.size(); i++)     {         of << spec_x[i] << "\t\t\t" << spec_y[i] << "\t\t\t" << freq[i]<<endl;     }     of << "end" << endl;     of.close(); } 

this function supposed write spectrum data (calculated earlier in program) , write file. spectrum data won't cause problem, will. error in loop. here error window:enter image description here

you're passing 3 vectors function:

const vecdoub& spec_x, const vecdoub& spec_y, const vecdoub& freq 

but never check have same size.

in loop (not "second" loop said in question, there's 1 loop in code posted), you're iterating on spec_x , use same index i index other 2 vectors.

what if 1 or both of other 2 vectors have smaller size spec_x? you're indexing out of bounds cause error you're seeing.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -