Is it possible to store 0x0 in strings as regular data? or is this used for null terminator? I wrote this simple function for use in networking:
string ForceSize(string str,int size,char fillerchar)
{
if(str.size()>size)return str.substr(0,size);
int charstoadd=size-str.size();
char * filler = new char[charstoadd];
for(int i=0;i<charstoadd;i++)filler=fillerchar;
string temp = str + filler;
delete filler;
return temp;
}
If fillerchar is 0x0 (which will be the case in networking usually) the function does not seem to work. My guess is that it sees the first one and figueres its the end of the string.
Is there a way to get this to work? Or is the only way to send it directly? I want to be able to use this helper function as well as others to format a string, then send it all as one buffer. Would I get better luck with char arrays maybe? I don't want to revert to those, but I supose for networking its not really the end of the world as packets will only go up to a certain size so I can live with using char arrays.
string ForceSize(string str,int size,char fillerchar)
{
if(str.size()>size)return str.substr(0,size);
int charstoadd=size-str.size();
char * filler = new char[charstoadd];
for(int i=0;i<charstoadd;i++)filler=fillerchar;
string temp = str + filler;
delete filler;
return temp;
}
If fillerchar is 0x0 (which will be the case in networking usually) the function does not seem to work. My guess is that it sees the first one and figueres its the end of the string.
Is there a way to get this to work? Or is the only way to send it directly? I want to be able to use this helper function as well as others to format a string, then send it all as one buffer. Would I get better luck with char arrays maybe? I don't want to revert to those, but I supose for networking its not really the end of the world as packets will only go up to a certain size so I can live with using char arrays.