Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > pass a vector t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 13 Topic 43736 of 47561
Post > Topic >>

pass a vector to a void function?

by "John Brawley" <jgbrawley@[EMAIL PROTECTED] > Mar 6, 2008 at 04:35 PM

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@[EMAIL PROTECTED]
 http://tetrahedraverse.com
 




 13 Posts in Topic:
pass a vector to a void function?
"John Brawley"   2008-03-06 16:35:53 
Re: pass a vector to a void function?
"John Brawley"   2008-03-06 16:39:45 
Re: pass a vector to a void function?
"Default User"   2008-03-06 22:50:43 
Re: pass a vector to a void function?
"John Brawley"   2008-03-06 17:47:33 
Re: pass a vector to a void function?
"Default User"   2008-03-07 00:59:25 
Re: pass a vector to a void function?
"John Brawley"   2008-03-06 20:19:07 
Re: pass a vector to a void function?
happyasaclam111@[EMAIL PR  2008-03-06 18:29:27 
Re: pass a vector to a void function?
"John Brawley"   2008-03-06 22:02:48 
Re: pass a vector to a void function?
"John Brawley"   2008-03-06 22:31:09 
Re: pass a vector to a void function?
happyasaclam111@[EMAIL PR  2008-03-06 21:15:04 
Re: pass a vector to a void function?
"John Brawley"   2008-03-07 12:44:23 
Re: pass a vector to a void function?
Krice <paulkp@[EMAIL P  2008-03-06 23:59:10 
Re: pass a vector to a void function?
"John Brawley"   2008-03-07 12:31:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 3:40:40 CDT 2008.