473,486 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CString process '\0' in the middle of string

Hi,

I would apprecaite the followinghelp;

I need to pass a TCHAR * s = foo*.* \0 *h\0" to CString operator, but
it will stop reading input at teh first \0, how do I work around this
??

Thanks
Dave

Jul 23 '05 #1
1 2198
dave wrote:
I would apprecaite the followinghelp;

I need to pass a TCHAR * s = foo*.* \0 *h\0" to CString operator,


There is no such thing as 'TCHAR' or 'CString' in standard C++.
That is, you have selected the wrong forum to post your article
to. If you had asked how to create a corresponding
'std::basic_string', the answer would be simple:

/**/ char const cliteral[] = "foo*.+ \0 *h\0";
/**/ std::string s1(begin(cliteral), (end(cliteral) - 1));
/**/ wchar_t const wliteral[] = L"foo*.+ \0 *h\0";
/**/ std::wtring s1(begin(wliteral), (end(wliteral) - 1));

with suitable definitions of 'begin()' and 'end()', e.g. these:

/**/ template <typename T, int sz>
/**/ T* begin(T(&a)[sz]) { return a; }
/**/ template <typename T, int sz>
/**/ T* end(T(&a)[sz]) { return a + sz; }

Note that the arrays are one character too big: string literals
contain an additional terminating null character. Thus, you
need to substract "1" from the end to obtain a proper past the
end iterator.

BTW, note that the type of string literals is 'char const*' or,
for wide characters, 'wchar_t const*' (note the "const"). The
reason you can assign a string literal to a pointer to non-const
characters is to provide backward compatibility. You should not
rely on this assignment and a good compiler should warn about it
in default mode.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
5472
by: Rajesh Garg | last post by:
Why and in what situations is CString not preferred? RVG
6
24488
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
3
9122
by: nsyforce | last post by:
What is the correct way to convert a const char* to a CString? I'm somewhat of a newbie and have tried several ways. While they all convert ok, I'm using a profiler that shows a memory leak for...
25
9877
by: Gareth | last post by:
I want to do the following to strings: 1) Check if first four characters are "DATA" 2) Get the middle 'word' from the following string "DATA 123 xyz" (the middle word is variable length) -...
2
3926
by: mirek | last post by:
Hi, I'm trying to import my old code to the .NET using managed wrappers. I've read "Managed Extensions for C++ Migration Guide" document and was trying to do what it stated in it. For example if...
7
8212
by: Klaus Bonadt | last post by:
I have an existing VC6 application using the MFC. I am able to pass CString and other parameters from such a VC6 dll to an unmanaged MFC dll (compiled in Visual Studio .NET). Now I want to use...
5
6577
by: Paul | last post by:
Hi, Any one knows how to convert CString to LPCWSTR? Please advice, thanks! -P
3
688
by: Xiaoshen Li | last post by:
Dear All, I saw some people using #include <string.h> some people using #include <cstring> What is the difference between the two? I can find the file string.h at /usr/include. I don't...
5
2356
by: Randeh | last post by:
Short story: in a beginning C++ class in college, was in a car accident that caused central spinal stenosis, some new Schmorl's nodes, disc problems and an incredible amount of pain. So far I've...
0
7100
marktang
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,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
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,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
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...
0
5434
agi2029
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,...
0
3070
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...

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.