Hi
any idea why I am getting something like
main.cpp:177: error: invalid operands of types ‘const char [11]’ and ‘const char [8]’ to binary ‘operator+’
when trying to compile something like
int main(int argc, char* argv[])
{
string a = ".........." + ".......";
cout << a << endl;
}
how can I solve this, I have few lines and use + to concatenate them
together.
thanks 5 2391
Gary Wessle wrote:
Hi
any idea why I am getting something like
main.cpp:177: error: invalid operands of types 'const char [11]' and 'const char [8]' to binary 'operator+'
when trying to compile something like
int main(int argc, char* argv[])
{
string a = ".........." + ".......";
cout << a << endl;
}
how can I solve this, I have few lines and use + to concatenate them
together.
thanks
You think the above is concatinating literal strings but its actually
attempting to add their pointers. Which is not allowed (obviously) when
constructing the std::string.
try:
std::string a = "..........";
a += ".......";
or better:
std::string sline1(10, '.');
std::string sline2(5, '.');
std::cout << sline1 << " title " << sline2 << std::endl;
Gary Wessle wrote:
Hi
any idea why I am getting something like
main.cpp:177: error: invalid operands of types ‘const char [11]’ and ‘const char [8]’ to binary ‘operator+’
when trying to compile something like
int main(int argc, char* argv[])
{
string a = ".........." + ".......";
string a = string("..........") + ".......";
cout << a << endl;
}
how can I solve this, I have few lines and use + to concatenate them
together.
There is no :
string operator+( const char *, const char * )
Gary Wessle wrote:
Hi
any idea why I am getting something like
main.cpp:177: error: invalid operands of types ‘const char [11]’
and ‘const char [8]’ to binary ‘operator+’
when trying to compile something like
int main(int argc, char* argv[])
{
string a = ".........." + ".......";
cout << a << endl;
}
There's not a std::string operator + that take two char pointers.
how can I solve this, I have few lines and use + to concatenate them
together.
std::string a = ".......";
a += ".....";
Brian
"Gary Wessle" <ph****@yahoo.comwrote in message
news:m3************@localhost.localdomain...
Hi
any idea why I am getting something like
main.cpp:177: error: invalid operands of types 'const char [11]' and
'const char [8]' to binary 'operator+'
when trying to compile something like
int main(int argc, char* argv[])
{
string a = ".........." + ".......";
cout << a << endl;
}
how can I solve this, I have few lines and use + to concatenate them
together.
thanks
As explained, you are actually trying to add two char pointers. A few ways
around:
std::string a = "......";
a += ".....";
or
std::string a = std::string("...........") + "............";
On 16 Dec 2006 16:54:40 +1100, Gary Wessle <ph****@yahoo.comwrote in
comp.lang.c++:
Hi
any idea why I am getting something like
main.cpp:177: error: invalid operands of types ‘const char [11]’ and ‘const char [8]’ to binary ‘operator+’
when trying to compile something like
int main(int argc, char* argv[])
{
string a = ".........." + ".......";
cout << a << endl;
}
how can I solve this, I have few lines and use + to concatenate them
together.
In addition to Gianni's answer, there is one thing you can do that
only works for string literals in source code, namely leave out the
'+'.
The code:
string a = "abc" "def" "ghi";
....produces exactly the same result as:
string a = "abcdefghi";
And so does this:
string a = "abc"
"def"
"ghi";
String literals that are separated by nothing but white space are
concatenated by the preprocessor when compiling.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Krakatioison |
last post by:
My sites navigation is like this:
http://www.newsbackup.com/index.php?n=000000000040900000
, depending on the variable "n" (which is always a number), it will take me
anywhere on the site......
|
by: Stu Cazzo |
last post by:
I have the following:
String myStringArray;
String myString = "98 99 100";
I want to split up myString and put it into myStringArray.
If I use this:
myStringArray = myString.split(" ");
it...
|
by: John F Dutcher |
last post by:
I use code like the following to retrieve fields from a form:
recd =
recd.append(string.ljust(form.getfirst("lname",' '),15))
recd.append(string.ljust(form.getfirst("fname",' '),15))
etc.,...
|
by: Angus Leeming |
last post by:
Hello,
Could someone explain to me why the Standard conveners chose to typedef
std::string rather than derive it from std::basic_string<char, ...>?
The result of course is that it is...
|
by: Andrew |
last post by:
I have written two classes : a String Class based on the book " C++ in
21 days " and a GenericIpClass listed below :
file GenericStringClass.h
// Generic String class
|
by: zoro |
last post by:
Hi,
I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party
string handling library that includes some very useful string
functions, in particular I'm interested in BEFORE (return...
|
by: Badass Scotsman |
last post by:
Hello,
Using VB and ASP,NET I would like to be able to search a STRING for a
smaller STRING within, based on the characters which appear before and
after.
For example:
String1 = " That was...
|
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: ramu |
last post by:
Hi,
Suppose I have a string like this:
"I have a string \"and a inner string\\\" I want to remove space in
this string but not in the inner string"
In the above string I have to remove...
|
by: drjay1627 |
last post by:
hello,
This is my 1st post here!
*welcome drjay*
Thanks! I look answering questions and getting answers to other!
Now that we got that out of the way. I'm trying to read in a string and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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...
|
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,...
| |