473,581 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does "expected unqualified-id" mean?

3 New Member
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\M y Documents\subst ring and structures.cpp expected unqualified-id before '{' token
11 C:\Documents and Settings\Main\M y Documents\subst ring and structures.cpp expected `,' or `;' before '{' token

Could someone please explain to me what the "unqualifie d-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 92059
ilikepython
844 Recognized Expert Contributor
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\M y Documents\subst ring and structures.cpp expected unqualified-id before '{' token
11 C:\Documents and Settings\Main\M y Documents\subst ring and structures.cpp expected `,' or `;' before '{' token

Could someone please explain to me what the "unqualifie d-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 New Member
When I put the struct before main and get rid of the 2nd main, this appears:

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

Any ideas?
Jun 12 '07 #3
ilikepython
844 Recognized Expert Contributor
When I put the struct before main and get rid of the 2nd main, this appears:

14 C:\Documents and Settings\Main\M y Documents\subst ring and structures.cpp expected primary-expression before "name"
14 C:\Documents and Settings\Main\M y Documents\subst ring and structures.cpp expected `;' before "name"
14 C:\Documents and Settings\Main\M y Documents\subst ring and structures.cpp At global scope:
17 C:\Documents and Settings\Main\M y Documents\subst ring and structures.cpp expected unqualified-id at end of input
17 C:\Documents and Settings\Main\M y Documents\subst ring 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 New Member
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 Recognized Expert Contributor
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 New Member
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,501 Recognized Expert Moderator Expert
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

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

Similar topics

4
5221
by: Grzegorz Dostatni | last post by:
Good morning. I've got a Tkinter problem: File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 2310, in selection_present return self.tk.getboolean( TclError: expected boolean value but got "" Now a few weeks ago there was a similar problem with the boolean value. That's when the tcl started returning "???" for unknown fields in a
51
6925
by: Noam Raphael | last post by:
Hello, I thought about a new Python feature. Please tell me what you think about it. Say you want to write a base class with some unimplemented methods, that subclasses must implement (or maybe even just declare an interface, with no methods implemented). Right now, you don't really have a way to do it. You can leave the methods with a...
20
3210
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains...
39
3164
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the function changes the state of the object, it ought to be a member of that object." Reference Accelerated C++, A. Koenig, page 159.
92
6152
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
4
44471
by: CodeTilYaDrop | last post by:
I am still pretty new to programming, and I sometimes can not figure something out. I am getting an error with this line in my program: Public void count_syllables(int count_syllables) I get the error <identifier expected>. What does this mean. I can not seem to make it go away!?
1
3264
by: nagaraj | last post by:
In Dev C++, we tried to compile a application, but it will throw some peculiar error. please find it below "path/main.cpp expected `]' before ';' token" and the source code is "DWORD rtec_Stack __attribute__((aligned(4)));" is this problem of envirnment or else?
9
11173
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list even then I should be able to get correct value for the array element. I need value and state to be present in a single byte thats why I use macros. ...
2
11917
by: Bryan Vargas | last post by:
I keep getting the same "expected indented block" when ever I run my code. from myro import* init("simulator") def main(): for x in range(10): #repeats code in loop 10 times
1
10869
by: Amjad Raza Gill | last post by:
I am facing this problem during the migration from oracle to db2, pls. help to remove this error. I am new to DB2. DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0104N An unexpected token "" was found following "". Expected tokens may ...
0
7808
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8312
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6564
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1410
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.