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
179
Comments
10
Last update

More entries in Personal Blogs

More entries from shoyrumaster11

General chit-chat
Help Users
  • BakerMan
    I rather enjoy a life of taking it easy. I haven't reached that life yet though.
  • Xdqwerty @ Xdqwerty:
    updated ship of harkinian, gonna install some hd texture pack
  • Xdqwerty @ Xdqwerty:
    I might download rayman revolution for my ps3
  • BigOnYa @ BigOnYa:
    I may try the new ram site, and download more RAM to my Switch. Not sure if ddr3 is the right ram
    for it tho. Edit- no it uses floppy Ram, just like @AncientBoi
    +1
  • Xdqwerty @ Xdqwerty:
    aeiou
  • BigOnYa @ BigOnYa:
    And sometimes Z
  • SylverReZ @ SylverReZ:
    @K3Nv2, MAGA supporters be wearing tin foil hats lol.
    +1
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, whats maga?
  • BigOnYa @ BigOnYa:
    It stands for Maniacs Against General Acceptance
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, people rejecting general consensus about stuff?
    +1
  • BigOnYa @ BigOnYa:
    Yup, nuh its really just Trump followers
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, im not american so i dont care about trump
    +1
  • Xdqwerty @ Xdqwerty:
    or us elections
  • BigOnYa @ BigOnYa:
    Me niether, us north Koreans don't care
  • Xdqwerty @ Xdqwerty:
    good night
  • BakerMan @ BakerMan:
    i don't care either, even if i'm american
  • BakerMan @ BakerMan:
    truth be told, i agree with psi, i dislike both candidates, but i'd probably vote trump simply because the economy was better during his presidency
    +1
  • AngryCinnabon @ AngryCinnabon:
    Just be careful, if trump ends up winning and using project 2025 America might really change...for the worse.
  • AngryCinnabon @ AngryCinnabon:
    I'm not american and even that sends shivers down my spine.
  • AngryCinnabon @ AngryCinnabon:
    anything that offers trump an opportunity to become an actual dictator
    is bad in my book, i could care less if it wasn't for that...
  • K3Nv2 @ K3Nv2:
    Canada: America's Russia
  • NinStar @ NinStar:
    people are so dramatic that I can't even tell if they are being serious
  • Psionic Roshambo @ Psionic Roshambo:
    Why so serious!
  • Psionic Roshambo @ Psionic Roshambo:
    @BakerMan, yeah that's about the only reason I would vote for Trump over Biden.
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    In my opinion on all other factors they are pretty much the same.
    +1
    Psionic Roshambo @ Psionic Roshambo: In my opinion on all other factors they are pretty much the same. +1