Hello..
Is this:
the same as:Code:char *query = new char[512];
char *ptr = query;
*ptr++ = 0;
*ptr++ = 15;
*ptr++ = 0;
*ptr++ = 1;
string query = "01501";
?
If not, how should I define string query then?
Printable View
Hello..
Is this:
the same as:Code:char *query = new char[512];
char *ptr = query;
*ptr++ = 0;
*ptr++ = 15;
*ptr++ = 0;
*ptr++ = 1;
string query = "01501";
?
If not, how should I define string query then?
No it's not the same.
Try strcpy( query, "01501");
Seems to me it'd be more along the lines of memcpy(query, "\000\017\000\001", 4)
i'd be more along the lines of
std::string = "01501";
The problem is I just want to have c++ string the same as c string and I wonder what would be the right way, since c++ strings are better to use and are not NULL terminated.
Just use a std::string for everything.
When you absolutely need the c-string equivalent, because that's what some API function expects, then just use mystring.c_str() to get a const char * equivalent.
So would it be okay to do std::string str = "01501"; for what I want? Or would it be better to use vector <char> instead?
Or a vector of ints
It seems like you're not storing strings at all, so stop writing things between double quotes.
Its not actually a string, its a data that will be sent in binary mode through socket.
Do you know <bitset>? If not, check it out. It's got lots of binary functionality.
I have no idea how I should use it in this case..Quote:
Originally Posted by twomers
It's very handy for int-bit conversion and whatnot. Check it out. I'm sure I have mentioned it before on the forums.