Please Help! Can't understand this error meaning.

error: expected unqualified-id before '{' token {


PLease Help me! I'm brand new in C++ programming

#include <iostream>
#include <string>


using namespace std;



int main ()


{

struct movie_t;
int year;

string title, movie_t;
int year;
string mine, yours;


string movie_t, movie,title;
string mystr;

{
mine.title = "2001 A Space Odyssey";
mine.year = 1968;

}
{
cout <<"Enter title: ";
getline (cin, year, title);

}

{
cout <<"Enter year: ";
getline (cin, mystr) >> yours.year;

}
{

cout <<"My favorite movie is:\n";

}

return 0;

}
Last edited on
what is your code?
write your code here
It means that there's something before a { symbol in your code that's not legal.

More than that, we couldn't say, without seeing the code.

Here is it is.


#include <iostream>
#include <string>


using namespace std;



int main ()


{

struct movie_t;
int year;

string title, movie_t;
int year;
string mine, yours;


string movie_t, movie,title;
string mystr;

{
mine.title = "2001 A Space Odyssey";
mine.year = 1968;

}
{
cout <<"Enter title: ";
getline (cin, year, title);

}

{
cout <<"Enter year: ";
getline (cin, mystr) >> yours.year;

}
{

cout <<"My favorite movie is:\n";

}

return 0;

}
Why do you have a bunch of random brackets everywhere? And there are other errors code.

1
2
3
string mine, yours;
mine.title = "2001 A Space Odyssey";
mine.year = 1968;


What are you trying to do here? String doesnt have functions called title and year. It seems to me that you're having trouble understanding the basics.

These are the functions of string - http://www.cplusplus.com/reference/string/string/

Edit: Also that's not how the getline function works.

http://www.cplusplus.com/reference/string/string/getline/

Edit 2:

You can't name variables the same name.

You have 2 variables called year, two called movie_t and two called title. Change that.
Last edited on
Topic archived. No new replies allowed.