By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

What does "expected unqualified-id" mean?

P: 3
I am currently doing online tutorials for C++, and am pretty much stuck in a rut about this problem. It is saying that there's an expected unqualifed-id before '{' token (I will post the code in just a second) on line 11, and an expected ',' or ';' before '{' token also on line 11, however I don't have a clue what the first one means. The program is meant to save a user's name in a string variable within a structure, and to then show that name without the need to assign a pointer to it. Also, note that I am compiling this with the Dev-C++ (aka Devcpp) compiler, on a Windows XP system.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     struct database {
  8.            string name; // declares that the structure has a string
  9.            // in it called name.
  10. }
  11. {
  12.            int main()
  13. cout<<"Enter your name.\n"; //displays the obvious
  14. getline(cin, name, '\n'); // records the user's input into the string name,
  15. // and terminates the command when the user presses enter.
  16.        database employee01;
  17.        // declares the single structure and its contents
  18.        employee01.name = string name;
  19. cout<<"Your name should be: "<<employee01.name<<".\n";
  20. cin.get();
  21. }
  22. }
  23.  
11 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected unqualified-id before '{' token
11 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected `,' or `;' before '{' token

Could someone please explain to me what the "unqualified-id before" means, how to fix it, what I did wrong, and why it is the way that you say is the correct code?
Jun 12 '07 #1
Share this Question
Share on Google+
7 Replies


ilikepython
Expert 100+
P: 844
I am currently doing online tutorials for C++, and am pretty much stuck in a rut about this problem. It is saying that there's an expected unqualifed-id before '{' token (I will post the code in just a second) on line 11, and an expected ',' or ';' before '{' token also on line 11, however I don't have a clue what the first one means. The program is meant to save a user's name in a string variable within a structure, and to then show that name without the need to assign a pointer to it. Also, note that I am compiling this with the Dev-C++ (aka Devcpp) compiler, on a Windows XP system.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     struct database {
  8.            string name; // declares that the structure has a string
  9.                               // in it called name.
  10. }
  11. {
  12.            int main()
  13. cout<<"Enter your name.\n"; //displays the obvious
  14. getline(cin, name, '\n'); // records the user's input into the string name,
  15. // and terminates the command when the user presses enter.
  16.        database employee01;
  17.        // declares the single structure and its contents
  18.        employee01.name = string name;
  19. cout<<"Your name should be: "<<employee01.name<<".\n";
  20. cin.get();
  21. }
  22. }
  23.  
11 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected unqualified-id before '{' token
11 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected `,' or `;' before '{' token

Could someone please explain to me what the "unqualified-id before" means, how to fix it, what I did wrong, and why it is the way that you say is the correct code?
Ok first let me post your code:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     struct database {
  8.            string name; // declares that the structure has a string
  9.            // in it called name.
  10. }
  11. {
  12. int main()
  13.     cout<<"Enter your name.\n";          //displays the obvious
  14.     getline(cin, name, '\n');                   // records the user's input into the string name,
  15.                                                    // and terminates the command when the user presses enter.
  16.     database employee01;
  17.                                                   // declares the single structure and its contents
  18.     employee01.name = string name;
  19.     cout<<"Your name should be: "<<employee01.name<<".\n";
  20.     cin.get();
  21. }
  22. }
  23.  
There are a couple of errors:
1. You have two mains
2. Structs should be declared outside of main

I think you need something like this:
Expand|Select|Wrap|Line Numbers
  1. struct database
  2. {
  3.     string name;
  4. };
  5.  
  6. int main()
  7. {
  8.     database employee01;
  9.     string name;
  10.     cout << "Enter your name: ";
  11.     getline(cin, name);
  12.     employee01.name = name;
  13.     cout << "Your name is: " << employee01.name << "." << endl;
  14.     return 0;
  15. }
  16.  
Jun 12 '07 #2

P: 3
When I put the struct before main and get rid of the 2nd main, this appears:

14 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected primary-expression before "name"
14 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected `;' before "name"
14 C:\Documents and Settings\Main\My Documents\substring and structures.cpp At global scope:
17 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected unqualified-id at end of input
17 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected `,' or `;' at end of input

Any ideas?
Jun 12 '07 #3

ilikepython
Expert 100+
P: 844
When I put the struct before main and get rid of the 2nd main, this appears:

14 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected primary-expression before "name"
14 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected `;' before "name"
14 C:\Documents and Settings\Main\My Documents\substring and structures.cpp At global scope:
17 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected unqualified-id at end of input
17 C:\Documents and Settings\Main\My Documents\substring and structures.cpp expected `,' or `;' at end of input

Any ideas?
Could you please post the exact code that you used?
Jun 12 '07 #4

P: 3
Could you please post the exact code that you used?
Sure.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct database {
  5.            string name; // declares that the structure has a string
  6.            // in it called name.
  7. int main()
  8. {
  9. cout<<"Enter your name.\n"; //displays the obvious
  10. getline(cin, name, '\n'); // records the user's input into the string name,
  11. // and terminates the command when the user presses enter.
  12.        database employee01;
  13.        // declares the single structure and its contents
  14.        employee01.name = string name;
  15. cout<<"Your name should be: "<<employee01.name<<".\n";
  16. cin.get();
  17. }
  18. }
  19.  
Jun 12 '07 #5

ilikepython
Expert 100+
P: 844
Sure.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct database {
  5.            string name; // declares that the structure has a string
  6.            // in it called name.
  7. int main()
  8. {
  9. cout<<"Enter your name.\n"; //displays the obvious
  10. getline(cin, name, '\n'); // records the user's input into the string name,
  11. // and terminates the command when the user presses enter.
  12.        database employee01;
  13.        // declares the single structure and its contents
  14.        employee01.name = string name;
  15. cout<<"Your name should be: "<<employee01.name<<".\n";
  16. cin.get();
  17. }
  18. }
  19.  
You never put the closing brace on the struct. Also, remember that you need a semicolon as well. Did you see the code I posted in my previous reply?
Jun 12 '07 #6

P: 2
sorry, I have no idea - all replies to this question give alternative codes, but don't explain what unqualified-id means.

my850+ page book on C++ does not mention either id or unqualified in its index.
Jun 18 '19 #7

zmbd
Expert Mod 5K+
P: 5,397
Turps asked this question again here and with a fairly good answer by Dev7060:
https://bytes.com/topic/c/answers/97...sage-referring
Jun 18 '19 #8

Post your reply

Sign in to post your reply or Sign up for a free account.