473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

string::data() mem function

Hi,
I am wondering whether string class's member function data() returns a
string of chars without '\0'?
Thanks.

Aug 23 '05 #1
5 1478

we*****@yahoo.com skrev:
Hi,
I am wondering whether string class's member function data() returns a
string of chars without '\0'?
Thanks.


Yes it does. Although you in practical use often will be able to use
data() as a const string (because the implementation might well append
a zero for different reasons), you should use c_str() whenever you want
the C-style string.

/Peter

Aug 23 '05 #2
* we*****@yahoo.com:
I am wondering whether string class's member function data() returns a
string of chars without '\0'?


How did you start wondering about that, I wonder?

Anyway, check your documentation (you might also look five threads up in
this group).

Or, as they said in the old days, RTFM.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 23 '05 #3
we*****@yahoo.com wrote:
I am wondering whether string class's member function data() returns a
string of chars without '\0'?


'std::string::data()' returns the contents of the string as the string
has them, \0 _can_ be part of it if you say so:

std::string s(10, '\0'); // s has 10 chars, all '\0'

V
Aug 23 '05 #4
Actually, I am looking for sting::toByte() function, unfortunately, it
is not there for C++. I don't want to include the null byte into the
final buffer which will be TCPed to the other node.

Aug 24 '05 #5
<we*****@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Actually, I am looking for sting::toByte() function, unfortunately, it
is not there for C++. I don't want to include the null byte into the
final buffer which will be TCPed to the other node.


Umm... since you're going off the raw data, and aren't needing (nor wanting)
the null terminator, you obvoiusly then are needing to go off the length of
the data. Since you have a pointer to the beginning of the data, and the
length, what does it matter in the least if there is a null terminator or
not since you're just not going to use it? In fact, I don't believe that
you could be guaranteed that it's not null terminated, since it's past your
end of data it could contain anything (undefined) and might in fact contain
a null byte.

In other words: don't worry about it. Use .data() and .length() and don't
care if it's null terminated.
Sep 2 '05 #6

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

Similar topics

3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
4
by: Ralph Noble | last post by:
Does anyone know of a string function in Access that will allow me to count the number of instances one string occurs within another? Or if there is some sort of word count function? If there is,...
23
by: David Frank | last post by:
How can I write a string function that encloses the input string in quotes "string" ?? below works for the "123 operation but adding " to it clobbers the "123 main() { char...
2
by: zDog | last post by:
I found a lot of information on passing data from C# to a C++ dll What I cannot find is a way to return C++ structs of TCHAR string data back to the C# managed code! typedef struct // C++ data...
3
by: CrimeMaster | last post by:
Hi i have made a Key under the HKEY_LOCAL_MACHINE\Software\My Toolbar\Setting. i have placed some values under the Setting key. i m trying to access the values under that key and want to map them...
1
by: Michael Hesse | last post by:
Hi, I have a C++ DLL that I call from a VB.Net app. I need to call a function from VB in the DLL and get string data back. Any suggestions on how to do this? What kind of parameters do I use...
7
by: Matik | last post by:
Hi to everyone, My problem is, that I'm not so quite sure, which way should I go. The user is inputing by second part application a long string (let's say 128 characters), which are separated...
2
by: rn5a | last post by:
All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that are available in ASP are supported by ASP.NET as well except for the string function 'String'. The 'String' function takes...
3
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
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
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
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
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...
0
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
tracyyun
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 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.