Can someone please fix this C++ code?

For some reason, CodeBlocks is giving me errors for this code:

Code:
// example about structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct movies t {
  string title;
  int year;
} mine, yours;
void printmovie (movies t movie);
int main ()
{
    string mystr;
    mine.title = "2001 A Spce Odeyssey";
    mine.year = 1968;
    cout << "Enter title: ";
    getline (cin,yours.title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> yours.year;
    cout << "My favourite movie is:
 ";
    printmovie (mine);
    cout << "And your is:
 ";
    printmovie (yours);
    return 0;
}
void printmovie (movies_t movie)
{
    cout << movie.title;
    cout << " (" << movie.year << ")
";
}
// end of line

Here are my errors (in color coding)

Line 7: error: variable 'movies t' has initializer but incomplete type
Line 7: warning: extended initializer lists only available with -std=C++0x or -std=gnu++0x [enabled by default]
Line 8: error: expected primary-expression before 'title'
Line 8: error: expected '}' before 'title'
Line 8: error: expected ',' or ';' before 'title'
Line 10: error: expected declaration before '}' token

Can someone please give me a link or something that will help fix these problems.

My C++ IDE is CodeBlocks and i'm running Windows 7 64-bit edition

Comments

Looking the whole code, it seems you need to change "movies t" to "movies_t". The compiler brings up an error because you designated the name wrong. It has to be one full name rather than the two you set. The latter of your code suggests you meant to do that, but didn't by accident.

In fact, I found where you got the code - http://www.cplusplus.com/doc/tutorial/structures/
 
[quote name='DiscostewSM' timestamp='1347665010'] Looking the whole code, it seems you need to change "movies t" to "movies_t". The compiler brings up an error because you designated the name wrong. It has to be one full name rather than the two you set. The latter of your code suggests you meant to do that, but didn't by accident. In fact, I found where you got the code - http://www.cplusplus.com/doc/tutorial/structures/ [/quote]

Yeah, cplusplus.com was the one C++ tutorial which didn't give me a headache to look at. I'll try fixing the coding errors the next time I run CodeBlocks and i'll PM you about any more of this stuff if you are okay with that!
 
DiscostewSM is correct - the way the compiler sees it, the "space" means that the name of the variable has finished. The "t" pops out of nowhere for it and causes the error. In fact, you appear to know about it as later in the code, you refer to the struct as void printmovie (movies_t movie){...} :).

Keep it consistent and it's going to work dandy.
 
[quote name='Zantigo' timestamp='1347995273'] Oh cool, that sites tutorial looks good, thanks. I gave up trying C++ just because the tutorials are confusing ^_^ [/quote]

Yeah! If you give cplusplus.com a try, you should use it for your C/C++ tutourials
 

Blog entry information

Author
shoyrumaster11
Views
169
Comments
10
Last update

More entries in Personal Blogs

More entries from shoyrumaster11

General chit-chat
Help Users
    BakerMan @ BakerMan: m