I am trying to use the function adjacent_difference
from the numeric
library on the second element of each entry of a vector of pairs (vector<pair<double,double>>
). How can I do it?
Update: here's my code so far (obviously wrong xD):
vector <pair<double,double>> initvalues; //receives pairs with the structure (174.386, 10)
for(int i = 0; i < 10; ++i)
{
initvalues.push_back(make_pair(i, 2+i));
}
vector <pair<double,double>> result(initvalues.size()-1);
adjacent_difference((initvalues.second).begin(),(initvalues.second).end(), (result.second).begin());
initvalues
is my main vector that allocates pairs of valus with the structure (174.386, 10) as example. result
is the output I want and it will store the first entry of the initvalues
vector in the first pair entry and the adjacent_difference
in the second entry of the pair.
However, I obtain the following output in the terminal compiling the code I've pasted in here:
stack.C: In function ‘int main()’:
stack.C:16:35: error: ‘class std::vector<std::pair<double, double> >’ has no member named ‘second’
16 | adjacent_difference((initvalues.second).begin(), (initvalues.second).end(), (result.second).begin());
| ^~~~~~
stack.C:16:64: error: ‘class std::vector<std::pair<double, double> >’ has no member named ‘second’
16 | adjacent_difference((initvalues.second).begin(), (initvalues.second).end(), (result.second).begin());
| ^~~~~~
stack.C:16:87: error: ‘class std::vector<std::pair<double, double> >’ has no member named ‘second’
16 | nitvalues.second).begin(), (initvalues.second).end(), (result.second).begin());
| ^~~~~~