私はc ++にまったく慣れていません。
ベクトルのポインターが配列を指すようにする方法があるかどうか疑問に思っていました。
私のプログラムには、次のように、ベクトルの最初と最後の要素を指すベクトル反復子オブジェクトがあります。
vector<int>::iterator vb = vec.begin();
vector<int>::iterator ve = vec.end();
「result」という配列があります。
'vb' が 'result' の最初の要素を指し、've' が 'result' の最後の要素を指すようにしたいと考えています。
私はこれを試しました:
vb = &result;
int resultLen = result.size();
ve = &(result+resultLen);
しかし、私はこのエラーで終わった:
`error: no match for ‘operator=’ in ‘vb = & result’
次のようないくつかのバリエーションを試しました。
*vb = &result;
int resultLen = result.size();
*ve = &(result+resultLen);
それもうまくいきませんでした。
どんな助けでも大歓迎です、そして前もって感謝します!!
================================================== =========================== 更新。これは、私が書こうとしているプログラムの単純なバージョンです。
vector<int>::iterator vb = vec1.begin();
vector<int>::iterator ve = vec1.end();
int arr = {1,2,3}
int result [10];
while (True) {
subtraction (vb, ve, arr, arr+5, result);
// let's say the vector has {1,2,3,4,5}. I am subtracting array from vector like this: 12345 - 123 until it becomes less than 123.
/*I now need to update the vector from which I am subtracting the array to the result array.*/
vb = &result; //points to the first element of array
int resultLen = result.size();
ve = &result+resultLen; //points to the last element of array
}
ベクトルの更新は、私が問題を抱えているところです。