Alternatives for "using"

Oct 16, 2021 at 9:56am
I was wondering if there are any alternatives for "using"?

#include <iostream>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <vector>
#include <algorithm>
using namespace std;

int counter, selection_movie;
const int WIDTH = 77, MAXMOVIES = 15;

class Movie
{
public:
string name, day, time1, time2, time3;
};

using MOVIE = Movie[MAXMOVIES];
vector<string> movie_name(25);
vector<string> showtime1(25);
vector<string> showtime2(25);
vector<string> showtime3(25);

^instead of implementing it like this are there any other solutions?
Sry if this is a stupid question I'm still a newbie to C++
Oct 16, 2021 at 10:40am
Why not just a vector of Movie? You then don't need MOVIE as a c-style array.

 
vector<Movie> movies;

Oct 16, 2021 at 10:48am
If this is a mystery then it's probably back to the books and lectures.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <vector>
#include <algorithm>

using namespace std;

int counter, selection_movie;
const int WIDTH = 77, MAXMOVIES = 15;

class Movie
{
public:
    string name, day, time1, time2, time3;
    void print()
    {
        cout
        << name << ' ' << day << ' '
        << time1 << ' ' << time2 << ' ' << time3
        << '\n';
    }
};

int main()
{
    
    Movie MOVIES[MAXMOVIES];
    
    // ARRAY OF MOVIES
    MOVIES[0] = Movie{"War and peace", "Wednesday", "10:30", "3:30", "7:30"};
    MOVIES[1] = Movie{"Blue & Gray", "Thursday", "11:30", "4:30", "8:30"};
    
    for( int i = 0; i < 2; i++)
        MOVIES[i].print();
    cout << '\n';
    
    // VECTOR OF MOVIES
    vector<Movie> movie_vec;
    
    movie_vec.push_back(MOVIES[0]);
    movie_vec.push_back(MOVIES[1]);
    
    for(auto i: movie_vec)
        i.print();
    cout << '\n';
}

War and peace Wednesday 10:30 3:30 7:30
Blue & Gray Thursday 11:30 4:30 8:30

War and peace Wednesday 10:30 3:30 7:30
Blue & Gray Thursday 11:30 4:30 8:30

Program ended with exit code: 0


Oct 16, 2021 at 1:06pm
this is a repeated topic from last week, and all the tail chasing that ensued to understand why they wanted to remove the using and what was really being asked for etc.
Last edited on Oct 16, 2021 at 1:06pm
Oct 17, 2021 at 10:43am
I was wondering if there are any alternatives for "using"?

Clearly there are, especially given that was what was being asked for. The alternative is not to use using at all. The supplementary comments about vectors and c-style arrays is a bonus from several of us. 2 out of 3 being constructive isn't too bad I suppose.
Oct 17, 2021 at 1:02pm
Which particular "using" are you trying to remove?
Oct 17, 2021 at 1:04pm
LOL
Topic archived. No new replies allowed.