array using vectors Or there is any better approach ? int main(){
string name="Honey Bansal";
vector <char> name_arr(name.begin(),name.end());
for(int i=0;i<name_arr.size();++i){
cout<<name_arr[i];
}
return 0;
}
if you need them dynamically sized then yes it's good enough
I am getting correct output , Idk about null char at the end.
Why?
C-like strings that are char arrays have to finish with a 0
why not.
can we do the same using new and delete ? or this way is most optimized ?
yeah I know that. But in this case, I did not explicitly added null char
What is your problem with storing strings in std::string?
All of the neccessary optimizations are already done in std::string.
Обсуждают сегодня