i have a function which the input is Cstring but i have a char array which i want to put in the fuction.
how can i do this?
by the way, what is CString?
i have a function which the input is Cstring but i have a char array which i want to put in the fuction.
how can i do this?
by the way, what is CString?
A char array is a C-string.
but how can i copy the char array to the Cstring?
the Cstring is define in a class , when i use strcpy, error said that
cant convert type "Class Cstring" to char*
Are you using a c-string (char * or char[]) or a user defined class String??? If it is the latter you can´t assign two different classes without a conversion.
A char string can be copied to a CString by doing:
And pass a char string to a function which the input is CString.Code:char strString[] = "this is a char string"; CString cstring; cstring = CString( strString );
Code:foo( CString( strString ) );
Last edited by Scarlet7; 04-27-2003 at 03:03 AM.
u can also do something like this..
Or u could always define both either as char[] or char* and then use strcpy which is imho the easiest way to do it..Code:#include <iostream> #include <string.h> using namespace std; int main() { char bob[10] = "bob"; char* doh = "yomama!"; unsigned int i =0; while(i < (strlen(doh))) bob[i++] = doh[i++]; cout <<bob<<endl<<doh<<endl; return 0; }
Luigi
// I use Xcode 1.1 && CodeWarrior 8.3
// When on Mac Os X 10.3.2
// I use Microsoft Visual C++ 6.0
// When on windows XP
^^^^^^^^^^^^^^^^^^^^^^^^^^^Originally posted by Luigi
u can also do something like this..
Or u could always define both either as char[] or char* and then use strcpy which is imho the easiest way to do it..Code:#include <iostream> #include <string.h> using namespace std; int main() { char bob[10] = "bob"; char* doh = "yomama!"; unsigned int i =0; while(i < (strlen(doh))) bob[i++] = doh[i++]; cout <<bob<<endl<<doh<<endl; return 0; }
This is you posting without understanding.
>while(i < (strlen(doh)))bob[i++] = doh[i++];
How many times is i being incrementing per loop! i++ twice
Isn't this thread talking about how to copy the char array to a CString!
Last edited by Scarlet7; 04-26-2003 at 03:38 PM.
sorry for trying to help
i++ twice thing.. ur right my bad i made this in 5 sec..
I guess from now on ill just ask question and wont bother trying to help others if i get answered like this..
Luigi
// I use Xcode 1.1 && CodeWarrior 8.3
// When on Mac Os X 10.3.2
// I use Microsoft Visual C++ 6.0
// When on windows XP
Hi Luigi, don't worry about it. I once posted void main() on this forum which is a big sin around here, much worse than the i++ thing.
How about:
char* foo="string";
Cstring mystring(foo);
It's a more effecient form of what scarlet said.
this is a very simple method
Code:public: void ToCString(CString* outputString) { if(outputString == NULL)outputString = new CString(); outputString->Empty(); for(int i=0;i<cbData;i++) { outputString->AppendChar(pbData[i]); } }