CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Why data() appends a NULL character at the end of string? topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2010, 10:46 PM
Junior Member
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
LarryChen is on a distinguished road
| More
Red face Why data() appends a NULL character at the end of string?

As we know member function data() defined by string won't append a NULL character at the end of string. But I found it still appends a NULL character at the end of string. Please check the following code,
Code:
int main() 
{
	string s = "Mike";

	char* q = const_cast<char*>(s.data());

	while(*q)
	{
		q++;
	}

	return 0;
}
Debug this piece of code, you will find out there is a NULL character at the end of string. Why?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
get data from webpage? Marezzi C# Programming 0 10-29-2008 09:48 AM
data store en0ne C# Programming 5 07-27-2008 02:58 PM
How to insert a string into string? Tran C Programming 3 05-21-2008 09:51 PM
Print Japaneese character on Linux terminal & debugging problem rajeshgalla C Programming 0 04-14-2008 03:01 AM
msdos character mode console programming- multiple windows HowardL Driver Development 0 08-05-2007 11:35 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 05:01 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board