dimanche 31 mai 2020

How to merge vectors returned from function?

I have a function that returns a vector of strings and inside my main function I would like to combine all the vectors returned from the function. However I keep hitting an error vector iterators incompatible, but I make sure I return a ptr from the function so the vector is not deleted when the function ends.

const unique_ptr<vector<string>> loadTransactions(string filename){
    unique_ptr<vector<string>> transactions = make_unique<vector<T>>();
    //some processing
    return transactions;
}
int main(){
    vector<string> allTransactions;
    for(int i =0; i< 10; ++i){
        unique_ptr<vector<string>> transactions = loadTransactions("filename");
        allTransactions.insert(allTransactions.end(), transactions->begin(), transactions->end());
}

Aucun commentaire:

Enregistrer un commentaire