Anyone knows how to convert a LPCTSTR to an STL striung?. Can't seem to
finda nyting (that dosen't blab on for several pages) on the net about
how to do this 10 17289
Lucy Ludmiller wrote:
Anyone knows how to convert a LPCTSTR to an STL striung?. Can't seem
to finda nyting (that dosen't blab on for several pages) on the net
about how to do this
typedef std::basic_string<TCHARtstring;
LPCTSTR pstz;
// ...
tstring tstr(ptsz); // construct a tstring from an LPCTSTR
// ...
Now, if you always want a narrow string (std::string), regardless of whether
it's a Unicode build or not, then you'll have to insert a narrowing
conversion from TSTR to char*, e.g. using wcstombs or WideCharToMultiByte.
Generally though, what you want it a std::basic_string of the same
"wideness" as TCHAR, so the simple typedef will do the trick.
-cd
>Anyone knows how to convert a LPCTSTR to an STL striung?. Can't seem
>to finda nyting (that dosen't blab on for several pages) on the net about how to do this
typedef std::basic_string<TCHARtstring;
LPCTSTR pstz;
// ...
tstring tstr(ptsz); // construct a tstring from an LPCTSTR
Just make sure that ptsz is different from NULL before you do this.
--
Kind regards,
Bruno van Dooren br**********************@hotmail.com
Remove only "_nos_pam"
Bruno van Dooren [MVP VC++] wrote:
>>Anyone knows how to convert a LPCTSTR to an STL striung?. Can't seem to finda nyting (that dosen't blab on for several pages) on the net about how to do this
typedef std::basic_string<TCHARtstring;
LPCTSTR pstz; // ... tstring tstr(ptsz); // construct a tstring from an LPCTSTR
Just make sure that ptsz is different from NULL before you do this.
Hi Bruno,
Any idea why Windows developers (not people who develop apps for
Windows, but people who develop Windows + the SDK) likes doing a
misleading #define on pointer so much?
I've been doing this for sometime so it doesn't surprise me anymore, but
I've seen many cases of people who just started and don't realize that
LPCTSTR is a const TCHAR* and think that it's some non-pointer magic
string and as such no memory allocation necessary, etc. What's wrong
with const TCHAR*, really?
Thanks,
Ray
Ray wrote:
Bruno van Dooren [MVP VC++] wrote:
>>>Anyone knows how to convert a LPCTSTR to an STL striung?. Can't seem to finda nyting (that dosen't blab on for several pages) on the net about how to do this typedef std::basic_string<TCHARtstring;
LPCTSTR pstz; // ... tstring tstr(ptsz); // construct a tstring from an LPCTSTR
Just make sure that ptsz is different from NULL before you do this.
Hi Bruno,
Any idea why Windows developers (not people who develop apps for
Windows, but people who develop Windows + the SDK) likes doing a
misleading #define on pointer so much?
I've been doing this for sometime so it doesn't surprise me anymore,
but I've seen many cases of people who just started and don't realize
that LPCTSTR is a const TCHAR* and think that it's some non-pointer
magic string and as such no memory allocation necessary, etc. What's
wrong with const TCHAR*, really?
In the days of different pointer sizes (near, far, huge, etc), it was
helpful to have typedefs. Even without those issues anymore, many C and C++
programmer prefer to use a typedef instead of retyping a compound type every
time.
As to why someone would think it's something special, or doesn't need the
same care for memory management that any other pointer deserves, I couldn't
say.
-cd
Carl Daniel [VC++ MVP] wrote:
In the days of different pointer sizes (near, far, huge, etc), it was
helpful to have typedefs. Even without those issues anymore, many C and C++
programmer prefer to use a typedef instead of retyping a compound type every
time.
Oh... no wonder. That explains it. Thanks Carl :)
As to why someone would think it's something special, or doesn't need the
same care for memory management that any other pointer deserves, I couldn't
say.
Yeah... I suppose it's because one has expected a pointer to have a *
when you define it. e.g.: it's clearer to have
void blah(const TCHAR* b)
instead of
void blah(LPCTSTR b)
although after a while of Win programming it's kinda becomes a habit.
Cheers
Ray
>
-cd
On Tue, 05 Sep 2006 20:49:27 +0800, Ray <ra********@yahoo.comwrote:
>Carl Daniel [VC++ MVP] wrote:
>In the days of different pointer sizes (near, far, huge, etc), it was helpful to have typedefs. Even without those issues anymore, many C and C++ programmer prefer to use a typedef instead of retyping a compound type every time.
Oh... no wonder. That explains it. Thanks Carl :)
>As to why someone would think it's something special, or doesn't need the same care for memory management that any other pointer deserves, I couldn't say.
Yeah... I suppose it's because one has expected a pointer to have a * when you define it. e.g.: it's clearer to have
void blah(const TCHAR* b)
instead of
void blah(LPCTSTR b)
although after a while of Win programming it's kinda becomes a habit.
It all makes sense when you understand the naming conventions.
"LP" means "long pointer", the "long" referring as mentioned to the
days when Intel CPU's used either long (segment-offset) or short
(offset only) pointers. The "C" means constant. And, of course,
"TSTR" means string of TCHAR.
Virtually all Windows pointer types have LP or P names.
I know people rail against such naming conventions but I find it
useful (provided they are accurate).
While we're at it, I just found out that PTCHAR isn't the same as
LPTSTR. The following code won't compile:
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, TCHAR* argv[])
{
PTCHAR p = 0;
}
If the two include directives change places, OR if LPTSTR stands instead
of PTCHAR then it will compile.
Mihajlo Cvetanović wrote:
While we're at it, I just found out that PTCHAR isn't the same as
LPTSTR. The following code won't compile:
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, TCHAR* argv[])
{
PTCHAR p = 0;
}
If the two include directives change places, OR if LPTSTR stands instead
of PTCHAR then it will compile.
Ugh... there you have another reason to have a simple TCHAR* instead of
these defines.
Ray
r norman wrote:
"LP" means "long pointer", the "long" referring as mentioned to the
days when Intel CPU's used either long (segment-offset) or short
(offset only) pointers. The "C" means constant. And, of course,
"TSTR" means string of TCHAR.
Sure, one can learn how to decode this information, and be able to deal
with these typedefs. But the question is not whether you can do it or
not, but how long it takes.
It takes an instant to understand
const TCHAR* b
and 15-25 seconds to decrypt
LPCTSTR b
Tom
On Wed, 20 Sep 2006 11:15:07 -0700, Tamas Demjen <td*****@yahoo.com>
wrote:
>r norman wrote:
>"LP" means "long pointer", the "long" referring as mentioned to the days when Intel CPU's used either long (segment-offset) or short (offset only) pointers. The "C" means constant. And, of course, "TSTR" means string of TCHAR.
Sure, one can learn how to decode this information, and be able to deal with these typedefs. But the question is not whether you can do it or not, but how long it takes.
It takes an instant to understand const TCHAR* b
and 15-25 seconds to decrypt LPCTSTR b
Compared to learning all the esoterica of Windows and MFC and STL and
whatever, that is the least of the problems. If you use Microsoft
specific library functions you have to use Microsoft specific
terminology. If you use STL, you have to use STL terminology. If you
use standard C++ you have to use standard C++ terminology. It is not
easy. So don't use LPCTSTR's if you don't like them! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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: Christopher Benson-Manica |
last post by:
Let's say I have a std::string, and I want to replace all the ','
characters with " or ", i.e. "A,B,C" -> "A or B or C". Is the
following the best way to do it?
int idx;
while(...
|
by: Jason Heyes |
last post by:
Does this function need to call eof after the while-loop to be correct?
bool read_file(std::string name, std::string &s)
{
std::ifstream in(name.c_str());
if (!in.is_open())
return false;
...
|
by: Erik Wikström |
last post by:
First of all, forgive me if this is the wrong place to ask this question,
if it's a stupid question (it's my second week with C++), or if this is
answered some place else (I've searched but not...
|
by: Patrick Kowalzick |
last post by:
Dear NG,
I would like to change the allocator of e.g. all std::strings, without
changing my code. Is there a portable solution to achieve this?
The only nice solution I can think of, would be...
|
by: Nemok |
last post by:
Hi,
I am new to STD so I have some questions about std::string because I
want use it in one of my projects instead of CString.
1. Is memory set dinamicaly (like CString), can I define for...
|
by: FBergemann |
last post by:
if i compile following sample:
#include <iostream>
#include <string>
int main(int argc, char **argv)
{
std::string test = "hallo9811111z";
std::string::size_type ret;
|
by: Peter Olcott |
last post by:
Is there anyway of doing this besides making my own string from scratch?
union AnyType {
std::string String;
double Number;
};
|
by: Jacek Dziedzic |
last post by:
Hi!
I need a routine like:
std::string nth_word(const std::string &s, unsigned int n) {
// return n-th word from the string, n is 0-based
// if 's' contains too few words, return ""
//...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |