I am having some problem here.
let' say that
string c="Hello";
char a[5];
how can i convert the string to a character array? Urgent
I am having some problem here.
let' say that
string c="Hello";
char a[5];
how can i convert the string to a character array? Urgent
you could increment your string and place all individually indexed location of the string into each individual location of the character array. you could do it with one loop, a string, and a char array. i unfortunatly do not recall any premade function to do this instantly.
Last edited by xviddivxoggmp3; 04-17-2005 at 11:01 PM.
"Hence to fight and conquer in all your battles is not supreme excellence;
supreme excellence consists in breaking the enemy's resistance without fighting."
Art of War Sun Tzu
The string class contains a function that returns the string as a character array:
Code:string c="Hello"; strcat(a, c.c_str()); // the character array a will now contain "Hello"
thank you
Code:#include <iostream> #include <cstring> #include <string> int main() { std::string str1 = "Hello"; char str2[str1.length() + 1]; //we can't just use length that would result in not null terminating std::strcpy(str2,str1.c_str()); std::cout<<"str1.length() = "<<str1.length()<<std::endl;//here is proof :) std::cout<<"str1 = "<<str1<<std::endl; std::cout<<"str2 = "<<str2<<std::endl; std::cin.get(); return 0; }
Woop?