+ 9
C++ std::vector
Hi, I've a std::vector<std::string> vec1 which has 8 elements (thanks push_back) I've another std::vector<std;;string> vec2, wich also has 8 elements. I want to copy all vec2 elements on vec1, to refresh the data of vec1 how ?
17 Respuestas
+ 14
You can easily to that.
vec1.clear() // Clears the vector.
vec1.swap(vec2) // Copies the content.
+ 4
Boy lr girl nurse ? (Good field !)
+ 4
I'm on programming school in university
+ 3
😄 ... please believe me. It was just coincidence. I am not in your head. I will answer you after work. My boss seems not amused.
+ 3
Hahaha ok no problem ^^ you work in what ?
+ 2
Nulpe thx I'll show you a code (that actually doesn't work) like that you'll know how I wanted to do
+ 2
I didn't waiting for girl nurse haha, just to be curious ans know you a bit ^^
+ 1
If you want to define your vector in a class, I have an example for you. 😁
https://code.sololearn.com/c25v4J4CiyHQ/?ref=app
+ 1
NoxFly a simple assignment is enough
vec1=vec2;
0
Its also posible to set your String-Vector with the constructor.
0
I work as nurse and i am a student at a technical university
0
Boy nurse ... Sorry ^^
0
Here to learn programming
0
NoxFly ドリアン I believe "cout<<testVec" is in C++ not valid. You need a loop to print every element of an array or vector,.
0
okoh victory you are welcome ... I am a noob 😁
0
You can also use move semantics
Vec1.assign(move(vec2));