This repository has been archived on 2023-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_cpp/seminar03_initialization/06_new/main.cpp
2022-10-22 18:26:37 +03:00

34 lines
755 B
C++

#include <iostream>
#include <string>
#include <string_view>
using namespace std;
int main() {
int *x = new int{123};
cout << *x << endl;
string *str = new string{"Cats and Dogs"};
cout << *str << endl;
int *xs = new int[]{10, 20, 30, 40, 50};
for (int i = 0; i < 5; ++i)
cout << xs[i] << " ";
cout << endl;
string *strs = new string[]{"Cat", "Dog", "Mouse"};
for (int i = 0; i < 3; ++i)
cout << strs[i] << " ";
cout << endl;
string_view *str_views = new string_view[]{strs[0], strs[1], strs[2]};
for (int i = 0; i < 3; ++i)
cout << str_views[i] << " ";
cout << endl;
delete x;
delete str;
delete[] xs;
delete[] strs;
delete[] str_views;
}