473,785 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What means expected unqualified-id before string constant on C++?

2 New Member
Hi to everybody, I'm a learner of C++. I'll really appreciate if you can help me or teach me something.

Thank you in advance.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3.  
  4. int main()
  5. {
  6.     std::cout << "Introduce your first name:";
  7.     std::string name;
  8.     std::cin >> name;
  9.  
  10.     //build the message that I intend to write.
  11.     const std::string greeting = "Hello, "+name+"!";
  12.  
  13.     //build the space line.
  14.     const std::string spaces(greeting.size()." ");
  15.  
  16.     //build the frame of the top/down.
  17.     const std::string frame(greeting.size()."*");
  18.  
  19.     //printing the result.
  20.     std::cout << std::endl;
  21.     std::cout << "*"+frame+"*" << std::endl;
  22.     std::cout << "*"+spaces+"*" << std::endl;
  23.     std::cout << "*"+greeting+"*" << std::endl;
  24.     std::cout << "*"+spaces+"*" << std::endl;
  25.     std::cout << "*"+frame+"*" << std::endl;
  26.  
  27.     return 0;
  28. }
Errors
14 C:\Users\eq1001 2\Documents\Unt itled1.cpp expected unqualified-id before string constant
17 C:\Users\eq1001 2\Documents\Unt itled1.cpp expected unqualified-id before string constant
Dec 16 '10 #1
3 15384
hype261
207 New Member
Look at your code on lines 14 and 17.

Expand|Select|Wrap|Line Numbers
  1. //build the space line. 
  2. const std::string spaces(greeting.size()." "); 
  3.  
  4. //build the frame of the top/down. 
  5. const std::string frame(greeting.size()."*");
  6.  
This syntax is really wrong...

greeting.size() returns a value of size_t

size_t for a string I believe is an unsigned integer type. Using a ."*" has no meaning on a size_t nor any class or struct for that manner.

The correct syntax would be...
Expand|Select|Wrap|Line Numbers
  1. //build the space line. 
  2. const std::string spaces(greeting.size() , " "); 
  3.  
  4. //build the frame of the top/down. 
  5. const std::string frame(greeting.size() , "*");
  6.  
  7.  
Commas instead of a period.
Dec 16 '10 #2
Elohim
2 New Member
Thanks a lot for the answer, I don't know what happens to me with the comma ^^... The Problems was that I'm reading on a Kindle and is hard to distinguish the . with the , and the " with the '. I don't know how this part works (greeting.size( ),' ') I just get the Idea from Accelerated C++: Practical Programming by Example. But now is done.

Thanks again.

Fixed code:

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3.  
  4. int main()
  5. {
  6.     std::cout << "Introduce your first name:";
  7.     std::string name;
  8.     std::cin >> name;
  9.  
  10.     //build the message that I intend to write.
  11.     const std::string greeting = "Hello, "+name+"!";
  12.  
  13.     //build the space line.
  14.     const std::string spaces(greeting.size(),' ');
  15.  
  16.     //build the frame of the top/down.
  17.     const std::string frame(greeting.size(),'*');
  18.  
  19.     //printing the result.
  20.     std::cout << std::endl;
  21.     std::cout << "*"+frame+"*" << std::endl;
  22.     std::cout << "*"+spaces+"*" << std::endl;
  23.     std::cout << "*"+greeting+"*" << std::endl;
  24.     std::cout << "*"+spaces+"*" << std::endl;
  25.     std::cout << "*"+frame+"*" << std::endl;
  26.  
  27.     return 0;
  28. }
Dec 17 '10 #3
hype261
207 New Member
Here is a website that I use for looking up information on the STL.

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

The constructor you are using is this one...

string ( size_t n, char c );

which does the following...

Content is initialized as a string formed by a repetition of character c, n times.
Dec 18 '10 #4

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

Similar topics

12
17543
by: Elaine Jackson | last post by:
Is there a function that takes a number with binary numeral a1...an to the number with binary numeral b1...bn, where each bi is 1 if ai is 0, and vice versa? (For example, the function's value at 18 would be 13 .) I thought this was what the tilde operator (~) did, but when I went to try it I found out that wasn't the case. I discovered by experiment (and verified by looking at the documentation) that the tilde operator takes n to -(n+1)....
5
3267
by: Frank Hauptlorenz | last post by:
Hello Folks, does anybody know what these message in the db2diag.log means: 2003-12-10-09.49.33.250000 Instance:DB2 Node:000 PID:812(db2syscs.exe) TID:772 Appid:84B43C19.0E04.031210070405 sort/list_services sqlsSpillASORT Probe:10 Database:STORCH ibuff
2
1812
by: Frank Hauptlorenz | last post by:
Hello, the filename for Fix11 (DB2 V7.2) ends with SBDB. What does this mean? Grüße from Germany, Frank
3
13297
by: Joe DeAngelo | last post by:
When I try to compile a source code which should normally run I got this error message error CS0246: The type or namespace name 'XmlSchemaSet' could not be found (are you missing a using directive or an assembly reference Platform SDK 1.1 is successfuly installed (under Win2000+SP4) So how can cope with this problem? Joe
5
2845
by: Tom | last post by:
I have a function that restricts access to a page to logged in users. When a user who isn't logged in goes to the page, it will dynamically generate a login form. I'm trying to use it in conjunction with the free shared SSL certificate offered by my host. To use SSL, you would change a URL like this http://mydomain.com/page.php
4
3230
by: giannis | last post by:
I am a newbie at VB. When i try to remove an item from the BindingSource and try to delete this item from the database: BindingSource.RemoveCurrent() Me.TABLETableAdapter.Update(Me.DataSet.TABLE) i receive the message :
6
1616
by: Victor | last post by:
i found some example js. the character $ has been used a lot. What's that mean? can someone give me some reference on that? Thanks
5
1881
by: stevewilliams2004 | last post by:
I was wondering if someone could explain the output I am getting for the program below. What I expected from the main program output was "Cat" but instead I see "Mammal". The output is also included below. I got the same results with GCC 3.4.4 under cygwin as with MSDev studio 2003. Even stranger to me, if I change the catch statement to catch a Cat instead of a Mammal, the program crashes in the catch body, during the call to...
4
2715
by: suresh gani | last post by:
What are unqualified pointers ?
3
1438
by: =?Utf-8?B?U2N5dGhlbg==?= | last post by:
Hi all, I have some code similar to the following: C# MyClass mVer = ne w MyClass(); …in a member function mVar.SendEvent( new Event() );
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.