0

Can we eliminate usage of char* in c++

Hi all Sorry for very basic question. As we always say that we should prefer string over char*, is it safe to say that don't ever use char* and just go with string.

31st Mar 2021, 8:22 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Respostas
+ 2
In my opinion, yes. The use of char * should be replaced with the use of std::string_view and std::string in C++ programs. I really don't see the advantage of using the plain old C-style strings
1st Apr 2021, 6:21 PM
Anthony Maina
Anthony Maina - avatar
+ 2
It's not wise to say that don't use char* at all. Just that substituting char with string gives more flexibility as youve various add ons in string functions. So your code is pointer free (i mean to say that asterisk free and looks easy to read) and also pretty neat to understand. But where you deal with single char then go with char data type. But for names/address/simple words i generally prefer strings.
31st Mar 2021, 9:43 PM
patilkrunal
patilkrunal - avatar
0
I am not denying on char. It's must to use char for single character but concern is where is use case of char* over string ?
31st Mar 2021, 11:16 PM
Ketan Lalcheta
Ketan Lalcheta - avatar