please help!
noktalivirgul (41)
Oct 29, 2012 at 9:58am UTC
I have a code such that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
class ambientvar{
public :
float temperature;
float pressure;
float power;
ambientvar(){};
ambientvar(float ,float ,float );
};
ambientvar::ambientvar(float temp, float press, float pow){
temperature= temp;
pressure=press;
power=pow;}
int main(){
float mainpress,maintemp,mainpow,allvariables;
vector<ambientvar> list;
ifstream myfile ("example.txt" );
int j;
for ( j=0;j<7500;j++)
{ myfile >> allvariables;
int div,mod=j%3;
div=j/3+1;
if (mod==0)
maintemp = allvariables ;
if (mod==1)
mainpress=allvariables;
if (mod==2)
mainpow=allvariables;
//list.push_back(*ambi1)}}
ambientvar ambi(maintemp,mainpress,mainpow);
list.push_back(ambi);
}
vector<ambientvar>::iterator it;
ambientvar ambi2;
ambi2=list[5];
float ttt;
ambi2.temperature=ttt;
cout<<ttt;
But the result is always o what can be the reason for it???????
Last edited on Oct 29, 2012 at 9:58am UTC
Peter87 (3691)
Oct 29, 2012 at 11:22am UTC
You create ttt and prints it, but you never assign it a value.
noktalivirgul (41)
Oct 29, 2012 at 11:38am UTC
actuallt i am trying to assign it "the" value in the 5th object's temperature.
Peter87 (3691)
Oct 29, 2012 at 12:01pm UTC
The only place I can see that the program is outputting is on line 42, where it prints the value of ttt. Is this what you mean by "the result"?
noktalivirgul (41)
Oct 29, 2012 at 12:09pm UTC
yes. i want to see ttt as the value in list[5]-ambi2.temperature.
Peter87 (3691)
Oct 29, 2012 at 12:30pm UTC
Like this?
1 2
float ttt = ambi2.temperature;
cout<<ttt;
noktalivirgul (41)
Oct 29, 2012 at 12:50pm UTC
thank you this gave me a value different than 0 but also not the 5th ambi's temperature. 1 2
ambientvar ambi2;
ambi2=list[5];
I think from this line i should get an object with 3 variables. and if i write ambi.temperature i get temperature if a write ambi.press i get press and so on...
But ı only obtained 4th input from my file.
Peter87 (3691)
Oct 29, 2012 at 1:57pm UTC
Note that list[5] gives you the 6th element in list because the indices starts at zero.
Last edited on Oct 29, 2012 at 1:58pm UTC
Topic archived. No new replies allowed.