| noktalivirgul (41) | |
although y and the vectorm temp is defined as floats it gives an error about this line.y >> temp.at(j) ;error says: left operand has type 'float' right operand has type 'float' | |
|
|
|
| guestgulkan (2831) | |
|
Your thread subject says << but your text says >> But either way you cannot use the bitshift operators << or >> on float types. | |
|
Last edited on
|
|
| noktalivirgul (41) | |
| is there another way i send floats to vector? | |
|
|
|
| andywestken (1950) | |||
You can't "send" floats to a vector (are you thinking of cin >> usage here?). But, if 'y' is some random float and 'temp' is a vector of floats, you can set the value of an elementtemp.at(j) = y; // set the element at index k to y or temp[j] = y;(here, the vector must have a size of at least j + 1) or append an element to the back of the vector temp.push_back(y); // add y to the end of the vector (push_back increases the size by 1) For other things you can do with vector, see (e.g. insert) http://www.cplusplus.com/reference/stl/vector/ Andy PS But you can read a float from cin (or from a file using ifstream, etc) into a vector element if the vector is big enough.
operator>>, in this case the extraction operator, is intended for use with input streams. And as guestgulkan has already said, operator>>, as the right bit shift operator (e.g. m = m >> 3; // shift m 3 bits to the right ) only works with integers. | |||
|
Last edited on
|
|||
| noktalivirgul (41) | |||||
thank you so much but still have a problem. the float variable y is read from a file and the code i wrote is:
this code gives error: 1>orjin.cpp(18): error C2064: term does not evaluate to a function taking 1 arguments 1>orjin.cpp(19): error C2064: term does not evaluate to a function taking 1 arguments the lines 18 and 19 are the lines:
| |||||
|
|
|||||
| cire (1851) | |
You need to use either:v.at(i).at(j)or v[i][j]
| |
|
|
|
| noktalivirgul (41) | |
| thank you so much. | |
|
|
|
| noktalivirgul (41) | |
| how do ı send some variable to v(i)(j) | |
|
|
|
| Moschops (5961) | ||
v[i][j] = someVariable;
| ||
|
|
||
| noktalivirgul (41) | |
|
should i not use v.push_back?? how to define v? | |
|
|
|