is it possible to convert a type string to a char[]?
like
string s;
char[8] c;
can you copy the contents of c into s?? i so how
is it possible to convert a type string to a char[]?
like
string s;
char[8] c;
can you copy the contents of c into s?? i so how
Code:#include<iostream> #include<string> using namespace std; int main(){ char x[] = "aaaaaaaa"; string s; for(int i=0;i<sizeof(x);i++) s+=x[i]; }
Not 100% definite on this but if I was going to write a string class, I would have a constructor to take care of that. You can probably do this:
Code:char name[] = "endo"; string s( name );
Hey good, point, here this works with the string lib :
Just curious as to why considering a string is just a char array anyway? I mean why bother creating char x[] anyway?Code:#include <iostream> #include <string> int main(){ char x[] = "This is a test string"; string s; s = string(x); //type-caste to type string cout<<s; cin.get(); return(0); }