Storing information in C++?

Pages: 123
I am trying to make a program that can register new information and acces it on demand.
For exampel, i need to have a menu for accessing stored movies (format and title).
need to be able to store new movies,
search for movies and then be able to exit the program.

And my problem is that i am having a hard time understanding how to use vectors for exampel and i don't really understand what everything does.
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
#include <string>
#include <iostream>
#include <vector>

struct Movies
{
public:

    Movies()
    {
        MovieName = "[ERROR] NAME NOT SET";
    }

    Movies(std::string name)
    {
        MovieName = name;
    }

    void HelloMoviez()
    {
        std::cout << "Haider, I am movie " << MovieName << std::endl;
    }

private:
    std::string MovieName;
};

int main()
{
    std::vector<Movies> MovieList;

    Movies Movie1("Legoluniuminus");
    Movies Movie2;

    MovieList.push_back(Movie1); // add the movie to the end of the vector
    MovieList.push_back(Movie2);
    MovieList[0].HelloMoviez(); // access the movie like an array, this is Movie1
    MovieList[1].HelloMoviez(); // Movie2

    return 0;
}
Last edited on
i tried compiling this but i got an error at line 17, 29 and 69 odly enough
closed account (j2NvC542)
How can you have an error on line 69, if the code is only 41 lines long?
What are the errors?
I compiled it and it ran perfectly in Code::Blocks, my guess is you may have some ancient compiler, or you copied it wrong.

or maybe you have too many warning compiler arguments set, I don't have many of them turned on.
Last edited on
Huh?! Apparently his compiler has a lot of warning flags set or is brain dead because it says errors are } { and nothing. :-/ But I agree, how do you get a error in line 69 for a 41 line code file? :-/

Compiles fine for me too though.

Could he be trolling?
The code as it is obviously cannot link because it does not have an entry point like main(), so if it was probably created by the IDE and copy pasted there line numbers are not the same.
I thought about that, but I've used a lot of IDEs and I've never seen one give the code 28 extra lines in the code. Don't know though, guess we will see :).
i tried answering yesterday but could not access this page.
anyhow, i am using Dev-C++ 4.9.9.2.
When i press line 69 it points to 29.

17 invalid token
17 expected constructor, destructor, or type conversion before '<' token
17 expected `,' or `;' before '<' token
(no number) In function `int main()':
69 redefinition of `int main()'
29 `int main()' previously defined here
Last edited on
you have two mains, the one on line 29 is mine, the one on line 69 is yours.

delete everything in your file and copy paste only my code, then run it, it will work fine.

also those errors on line 17 don't exist, I have no < token
i did not edit anything before i compiled it, but i did try deleting it all and copying again and now it compiles but dissapears as soon as it starts
Yeah, some compilers don't pause a program before it terminates, mine (Code::Blocks) does so I don't worry about it.

http://cplusplus.com/forum/beginner/1988/ if you want to try fixing it yourself

but regardless, the code there is just an example, it isn't going to do what you want it to do.
well, i got it to compile now.
allthough i have no clue on how to actually add movies and being able to search for the movies.
since this code did nothing more than show two "movies"
That's because its nothing more than an example on how vectors work, what you're trying to is fairly hard, you'll need to look into sorting algorithms like bubble sort and quick sort, plus if you want to launch a program to watch the movie you'll need to run an external media player with arguments

start small, not big, or you will just get discouraged and stop programming.
unfortunatly this is for school, and i study online.

i don't need for it to actually play files, i only need it for a dummy program so to speak.

i only need the program to show movie names and format (blueray/dvd)
able to add movies into the list, and be ablo to search from the list.

so unfortunatly i have to do this :(
please i really need some help, i am knee deep in this stuff and i am so clueless
You wouldn't have been given this assignment unless you had previous programming knowledge, your teacher should have explained some parts of this already, using vectors and classes are pretty basic stuff you should learn within the first two months.

this guy has made over 60 videos and they are a really good introduction to c++, I suggest you go back to basics and follow it from the start, make sure that you code while you watch, watching isn't good enough.

http://www.youtube.com/watch?v=tyVhn0FWWB4

each one is about 10-15 minutes long so it shouldn't take you very long to get through them.
well, i am actually going through "programming" class faster than you would.
i have only been using c++ for 3 weeks and 2 assignments and now i got this.

why? well i have one week per assigment and i am obviously late with this one.

I am currently watching Lynda.com C++ lessons
and just to point it out, i can not change the pace i am studying in.
so i have to pretty much code this and another one which i have not seen yet until friday. with my limited skills, and the school don't care about me not knowing and i can not talk to the teachers since i am doing tmy studying online.
so i am alone with this :P
thats why i am cowering for help
of course you can change the pace your studying, study more, or better yet, code more, instead of wasting your time asking us to do your homework which isn't allowed on these forums.
Pages: 123