Answers for "c++ vector array"

C++
36

c++ vector

#include <vector>

int main() {
  std::vector<int> v;
  v.push_back(10); // v = [10];
  v.push_back(20); // v = [10, 20];
  
  v.pop_back(); // v = [10];
  v.push_back(30); // v = [10, 30];
  
  auto it = v.begin();
  int x = *it; // x = 10;
  ++it;
  int y = *it; // y = 30
  ++it;
  bool is_end = it == v.end(); // is_end = true
  
  return 0;
}
Posted by: Guest on March-17-2020
1

c++ vector

#include <vector>
#include <string>

int main() {
  std::vector<std::string> str_v;
  str_v.push_back("abc");
  str_v.push_back("hello world!!");
  str_v.push_back("i'm a coder.");
  for(auto it = str_v.beigin();it != str_v.end(); it++) {
  	printf("%sn",it->c_str());
  }
}
Posted by: Guest on September-10-2021

Browse Popular Code Answers by Language