C++ question: How can I print vector A in one line and vector B in another one (
ID: 3914990 • Letter: C
Question
C++ question:
How can I print vector A in one line and vector B in another one (all pushed back already)?
It keeps giving me the result in separate lines.
Can you please show me your result if it works? thanks!
Thanks
#include
#include
using namespace std;
vector append(vector a, vector b){
vector merge;
for (int i = 0; i < a.size(); i++){
merge.push_back(a[i]);
}
for (int i = 0; i < b.size(); i++){
merge.push_back(b[i]);
}
return merge;
}
int main(){
vector a = {1, 2, 3, 4};
vector b = {5, 6, 7, 8, 9};
vector result = append(a, b);
cout<<"Here is the final vector: ";
for (int i = 0; i < result.size(); i++){
cout<< result.at(i);
}
cout<
}
Explanation / Answer
#include #include using namespace std; vector append(vector a, vector b) { vector merge; for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.