Jan 18, 2016 at 9:33am UTC
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 Jan 18, 2016 at 12:34pm UTC
Jan 18, 2016 at 9:35am UTC
what is your code?
write your code here
Jan 18, 2016 at 12:13pm UTC
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.
Jan 18, 2016 at 12:34pm UTC
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;
}
Jan 18, 2016 at 2:07pm UTC
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 Jan 18, 2016 at 2:17pm UTC