?
Solved

Simple String Concat Question

Posted on 2003-02-25
7
Medium Priority
?
479 Views
Last Modified: 2012-08-13
LPCTSTR m_pszExeName; // I have this, its the exe name

char buf[128]; // I want to add this onto it it has a name in it
------------------

I want to concat a char buffer(up to 128 bytes) onto an LPCTSTR. What is the easiest way? The end reslt needs to be a concatanated LPCTSTR to use for CreateSeamphore.

HANDLE hSem = CreateSemaphore(NULL, 1, 1, MyConcatLPCTSTRgoesHere);


Thanks for the help,
Doug
0
Comment
Question by:DougC
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
vadik earned 80 total points
ID: 8019244
LPCTSTR lp = "FirstStr";
TCHAR buf[128] = "SecondStr"; // I think is better using
                             // TCHAR instead of char.
_tcscat(&buf[0], lp);

// Do something with buf... for example
HANDLE hSem = CreateSemaphore(NULL, 1, 1, &buf[0]);



0
 
LVL 6

Expert Comment

by:gj62
ID: 8020217
vadik -

Just a quick note - the order of your strings I think is backward.  

Buf would actually equal "SecondStrFirstStr" after concatenation.

I think he wants _tcscat(lp, buf);
0
 
LVL 1

Expert Comment

by:vadik
ID: 8020325
Just I thought that it's not good to change LPCTSTR because this is pointer to const. But this is only my oppinion.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:vadik
ID: 8020382
Just I thought that it's not good to change LPCTSTR because this is pointer to const. But this is only my oppinion.
0
 
LVL 6

Expert Comment

by:gj62
ID: 8020487
You are right, though MSFT shows examples of doing exactly that - anyhow, he'd be better off creating a new object and storing the concatenated string there...

e.g.

CString params;
params = lp + buf;

would probably be easiest...
0
 
LVL 1

Expert Comment

by:vadik
ID: 8020733
If you are using MFC :)
0
 
LVL 6

Expert Comment

by:gj62
ID: 8020945
True - bad assumption...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question