3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSerだけどC++のvectorで配列を扱ってみた

Posted at

下書きのまま残ってたので放出:

勉強中。

// JavaScript

var arr = [];
arr.push(101);
arr.push(-1);
arr.push(999);
for (var i=0, l=arr.length; i<l; i++) {
  var n = arr[i];
  console.log(i, n);
}
// C++

#include <vector>

std::vector<int> arr;
arr.push_back(101);
arr.push_back(-1);
arr.push_back(999);
for (int i=0, l=arr.size(); i<l; i++) {
  int n = arr[i];
  printf("%d, %d\n", i, n);
}

push_back()の逆はpop_back()だが、これは末尾を削除するだけで、値を返さない。(戻り値はvoid。) "_back"て何だろう?

参考:

3
4
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?