vector and sscanf
can I directly do this somehow??
ie
sscanf("%f",vect1.push_back());
??
at the moment I have to use
sscanf("%f",&x);
vect1.push_back(x);
TIA
you can not even do
vect1.push_back();
you have always to pass a value in push_back()
and push_back() returns void...
vect1.push_back();
you have always to pass a value in push_back()
and push_back() returns void...
// C code:float f[20]; // possibly uninitialized floatssscanf ("%f", &f[10]); // scan into the 11th element// STL code:vector<float> f (20); // initializes vector to 0.0sscanf ("%f", &f[10]); // scan into the 11th element
Gotta love STL.
operator[] already returns a reference
I think that it sould be
I think that it sould be
vector<float> f (20); // initializes vector to 0.0sscanf ("%f", f[10]); // scan into the 11th element
Well sscanf needs a pointer so it should probably be:
But I honestly have no idea if that will work.
vector<float> f (20); // initializes vector to 0.0sscanf ("%f", &(*f[10])); // scan into the 11th element
But I honestly have no idea if that will work.
quote:Original post by Scarab0
Well sscanf needs a pointer so it should probably be:
In many contexts there is no effective difference between references and pointers. Further more, the fact that a function takes a pointer as an argument doesn''t mean you must pass it an argument; it means the function will take the address of whatever argument you pass to it (with type restrictions). ie
int func( int *pInteger );int i = 255;func(&i); // note need to get address-of i using operator &.int j[25];// initialize j if necessaryfunc(j); // still valid; func() takes address of j[].int *k;k = new int[NUM_INTS]; // assume NUM_INTS to be a constantfunc(k); // same as func(j), only array is dynamic. func() still takes address of k[].
thanks for the answers but what I need to do is:
sscanf("%f",vect1.vert.push_back(float returned by sscanf ));
Thnks
sscanf("%f",vect1.vert.push_back(float returned by sscanf ));
Thnks
Are you listening (reading)? You can''t do it in one statement using push_back(); get over it! If your vector is already allocated (using resize(), for example), you can assign the value returned by sscanf() to the ith element. That''s it.
Just for the record, the proper sscanf statement is
pacrugby:
What you''re trying to do is impossible. Period. The others have made very good explanations why.
sscanf("%f", &f[10]);
pacrugby:
What you''re trying to do is impossible. Period. The others have made very good explanations why.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement