-
September 11th, 2009, 03:00 PM
#1
[RESOLVED] Just curious about std::string
Good evening lads.
OK. Lets say I make string
Code:
std::string dataBlock;
...........................................
//Fill that string with some data
.........................................
and presume that at some point I make
Code:
dataBlock[i] = '\0';
So what happens there. Does the compile see this place/address where was dataBlock[i] set to '\0', as empty memory and can writte there new stuff or not ?
I hope you understand what I mean. OC its g++.
Share and always try to give back more.
-
September 11th, 2009, 03:04 PM
#2
Re: Just curious about std::string
std::string can contain embedded '\0'. its just like any other char.
just make shure you never write to a location >= size().
Kurt
-
September 11th, 2009, 03:14 PM
#3
Re: Just curious about std::string
Ahh OK. Thank you Zuk
Share and always try to give back more.
-
September 11th, 2009, 06:54 PM
#4
Re: Just curious about std::string
couple of points:
1) '\0' is called the Null character.
2) This null character is used to mark the end of the ctring ( char [] or char * )
3) The std :: string doesn't treat null character any differently from any other char
Note - std :: string is a class with a lot of overloaded operator for easier use.
The following shows the above
Code:
#include <iostream>
#include <string>
using std :: cout;
using std :: endl;
using std :: string;
int main()
{
string dataBlock = "abcdefh";
dataBlock[2] = '\0';
dataBlock[3] = 'z';
cout << "dataBlock = " << dataBlock << endl;
return(0);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|