I prefer them too, but they are not compatible with other languages or most win32 api functions. If you are not concerned with either of those then by all means use std::string.
Edited 5 Years Ago by Ancient Dragon: n/a
The main reason for using const char* is because it is compatible and linkable with C. Many APIs and other libraries have C interfaces (you use the API via a collection of C-like functions). With these functions, you have no choice but to use types that exist in C, which includes primitive types like int, float, char, double, short, etc. and any pointer type (including C++ class pointers, since they are just normal pointers). In other words, you can't use pass-by-value of any class type (including std::string), and you can't use any pass-by-reference of any type.
The reason why C interfaces are used is mainly because C is so simple that it does not need to mangle function names to account for parameter types (which C++ has to do to achieve function overloading), and because types in C have a trivial byte alignment because it doesn't have to deal with virtual tables and multiple inheritance like C++ does. So, C interfaces are preferred for portability and binary compatibility, and along with that comes the burden of having to convert strings to const char* and vice versa (or sometimes write code that uses const char*, just to avoid converting back-and-forth all the time).
In internal code (code that doesn't use an API directly, or code that isn't at the interface of an API), if programmed in C++, I see absolutely no reason to use const char* instead of std::string. The only people using char* in these situations are those who suffer from the "C-hacker syndrome".
write a C++ program which take inputs from the user/keyboard and calculate his ZAKAT.
get the input from user may include
-Amount invested in business
-Amount given to other business partners as loan
-Amount payable to others
I made a prime number finder, it finds the nearest prime that is above and below any integer (Does not work that well with giant numbers.)
Made this in cpp.sh
Why would I need the x=y+1-1;?
x=y; just doesnt seem to work
Why is this?
And I know my coding ...
there are five tables (personTb, addressTb,churchTb) each holds data pertinent to an individual; (personAddress,personChurch) each hold the primary key for the person table and corresponding table IE personAddress holds primary key for addressTb.
both snippets work, my question is; Is my join correctly formatted?
select concat(personTb.p_fName,' ',personTb.p_mName,'. ',personTb.p_lName) ...