Language: C++

#include <algorithm>
#include <iostream>

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  if(!v.empty()) {
    std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(out, " "));
    out << v.back();
  } else {
    out << "";
  }
  return out;
}

int bubblesort(std::vector<int> &xs) {
  int len = xs.len();
  int cnt_swap = 0;
  bool flag = true;
  while(flag) {
    flag = false;
    for(int i = len - 1; i >= 1; --i) {
      if(xs[j] < xs[j - 1]) {
        std::swap(xs[j], xs[j - 1]);
        flag = true;
        cnt_swap++;
      }
    }
  }
  return cnt_swap;
}

int main(void) {
  int n;
  std::cin >> n;

  std::vector<int> xs;
  int x;
  for(int i = 0; i < n; ++i) {
    std::cin >> x;
    xs.push_back(x);
  }

  int cnt = bubblesort(xs);

  std::cout << xs << std::endl;
  std::cout << cnt << std::endl;

  return 0;
}

Compiler output:
a.cc:5:56: error: 'vector' in namespace 'std' does not name a template type
    5 | std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
      |                                                        ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <iostream>
  +++ |+#include <vector>
    3 | 
a.cc:5:62: error: expected ',' or '...' before '<' token
    5 | std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
      |                                                              ^
a.cc: In function 'std::ostream& operator<<(std::ostream&, int)':
a.cc:6:7: error: 'v' was not declared in this scope
    6 |   if(!v.empty()) {
      |       ^
a.cc:7:44: error: 'ostream_iterator' is not a member of 'std'
    7 |     std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(out, " "));
      |                                            ^~~~~~~~~~~~~~~~
a.cc:3:1: note: 'std::ostream_iterator' is defined in header '<iterator>'; this is probably fixable by adding '#include <iterator>'
    2 | #include <iostream>
  +++ |+#include <iterator>
    3 | 
a.cc:7:62: error: expected primary-expression before '>' token
    7 |     std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(out, " "));
      |                                                              ^
a.cc: At global scope:
a.cc:15:21: error: 'vector' is not a member of 'std'
   15 | int bubblesort(std::vector<int> &xs) {
      |                     ^~~~~~
a.cc:15:21: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:15:28: error: expected primary-expression before 'int'
   15 | int bubblesort(std::vector<int> &xs) {
      |                            ^~~
a.cc: In function 'int main()':
a.cc:36:8: error: 'vector' is not a member of 'std'
   36 |   std::vector<int> xs;
      |        ^~~~~~
a.cc:36:8: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:36:15: error: expected primary-expression before 'int'
   36 |   std::vector<int> xs;
      |               ^~~
a.cc:40:5: error: 'xs' was not declared in this scope; did you mean 'x'?
   40 |     xs.push_back(x);
      |     ^~
      |     x
a.cc:43:24: error: 'xs' was not declared in this scope; did you mean 'x'?
   43 |   int cnt = bubblesort(xs);
      |                        ^~
      |                        x
a.cc:43:26: error: 'bubblesort' cannot be used as a function
   43 |   int cnt = bubblesort(xs);
      |                          ^