469,326 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

What does "expected unqualified-id" mean?

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
7 85660
ilikepython
844 Expert 512MB
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
Warrax
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
844 Expert 512MB
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
Warrax
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
844 Expert 512MB
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
turps
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
5,400 Expert Mod 4TB
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.

Similar topics

4 posts views Thread by Grzegorz Dostatni | last post: by
51 posts views Thread by Noam Raphael | last post: by
20 posts views Thread by Steven T. Hatton | last post: by
39 posts views Thread by utab | last post: by
92 posts views Thread by Heinrich Pumpernickel | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.