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?
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");
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Seems to me it'd be more along the lines of memcpy(query, "\000\017\000\001", 4)
System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.
Useful resources:
comp.lang.c FAQ | C++ FQA Lite
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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..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.