pass a vector to a void function?
Hello once more....
I'm trying to learn vectors, by recoding my working program that uses
array[]s.
In order to know if it's doing what it's supposed to, I have to write a file
from the values in the vector, to feed to a separate graphic display
program.
I don't get it: nothing appears in the file.
I *know* for sure the array[] is proper, and full: I can see its values
using cout<<.
I've tried everything I could find on the web; my code should be right; the
vector itself works right, but I can't get the filewriter to write anything
into the file it creates....
//Outside of main() I make the vector:
using namespace std;
vector<double> pdbv;
long int pNum;
int endless=1;
//Here's the filewriter function:
void it8vout(const vector<double> &pdbv) {
ofstream it8vfil;
it8vfil.open ("it8vrawc.3d");
if (it8vfil.is_open()) {
for (long int k=0; k<(pNum*5); k+=5) {
double a=pdbv[0+k];
double b=pdbv[1+k];
double c=pdbv[2+k];
it8vfil<<a<<" "<<b<<" "<<c<<"\n"; }
}
it8vfil.close();
}
I'm calling it like this:
main() {
while (endless==1) {
//assume sane things happen (eternal loop)
if (kbhit()) { ch=getch(); switch(ch) {
case 's': it8vout(pdbv); cout<<"wrote snapshot files\n";break;
// (I hit 's' to call the filewriter........)
case ' ': cout<<pHi<<" "<<gRad<<" "<<x1<<" "<<y1<<" "<<z1<<"\n";break;
case 'q': goto Donedone;
default: cout << "Not a valid key.\n";
} } }
Donedone:
//......and again for a final write:
it8vout(pdbv);
return 0;
}
The program compiles, runs, I can see the values changing in the vector as
they're supposed to, but the filewriter just creates an empty file....
What'm I doing wrong?
Thanks
--
Peace
JB
jb@tetrahedraverse.com
Web: http://tetrahedraverse.com