Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1035
  • Last Modified:

Multiple String Concantenation in C++

What I am  trying to do is concatenate multiple strings together and store it in another string variable to use later. Below is my latest attempt at my problem.   I am new to C++ strings, so any help is appreciated.  Thanks for your time.

--Charly
string output << "Printing '" << fieldText[9] << "' using '" << printerName << "' on " << someDate << endl;
 
cout << output << endl;

Open in new window

0
dleehanson
Asked:
dleehanson
  • 2
2 Solutions
 
UrosVidojevicCommented:
0
 
IchijoCommented:
Change 'string' to 'ostringstream'.

Then if you later need to access it as a string (for example, to assign it to a string variable), call output.str().
ostringstream output;
output << "Printing '" << fieldText[9] << "' using '" << printerName << "' on " << someDate << endl;
cout << output << endl;

Open in new window

0
 
dleehansonAuthor Commented:
Thanks for the bump in the right direction.  I ended up using an ostringstream to get what I wanted.  Thanks again.

--Charly
ostringstream os;
os << "Printing '" << fieldText[9] << "' using '" << printerName << "' on " << someDate << endl;
std::string output(os.str());
cout << output;

Open in new window

0
 
dleehansonAuthor Commented:
Heh, that's what I get for not refreshing the page...

So I don't need to explicitly convert it to a string first then?  Awesome.  Thanks for the help you two.

--Charly
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now