Strings and vectors

std::string and std::vector, the two types you will use most.

Prefer string to char arrays and vector to plain arrays. Both grow as needed and free their own memory.

C++
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> marks = {72, 95, 60};
  marks.push_back(88);
  sort(marks.begin(), marks.end());
  for (int m : marks) {
    cout << m << " ";
  }
  cout << "\n" << marks.size() << "\n";

  string s = "Internship";
  cout << s.substr(0, 5) << " " << s.length() << "\n";
  return 0;
}
Output
60 72 88 95 
4
Inter 10
โ† Getting started with C++Classes and objects โ†’