What is use of c_str function In c++

c_str returns a const char* that points to a null-terminated string (i.e. a C-style string). It is useful when you want to pass the “contents”¹ of an std::string to a function that expects to work with a C-style string. For example, consider this code: See it in action. Notes: ¹ This is not entirely true because an std::string (unlike a C string) … Read more

What is the LD_PRELOAD trick?

If you set LD_PRELOAD to the path of a shared object, that file will be loaded before any other library (including the C runtime, libc.so). So to run ls with your special malloc() implementation, do this:

Printing hexadecimal characters in C

You are seeing the ffffff because char is signed on your system. In C, vararg functions such as printf will promote all integers smaller than int to int. Since char is an integer (8-bit signed integer in your case), your chars are being promoted to int via sign-extension. Since c0 and 80 have a leading 1-bit (and are negative as an 8-bit integer), they are being sign-extended while the others in your … Read more

How do I solve the following errors: “Undefined reference to WinMain”, “[Error] Id returned 1 exit status”?

This error means that the linker is looking for a function named WinMain to use as the entry point. It would be doing that because you configured the project to target the GUI subsystem, but did not provide a WinMain function. My guess is that you want to produce a console application and have provided a main function. Target the console … Read more

Using ssize_t vs int

There’s no guarantee in the POSIX standard that sizeof(int) >= sizeof(ssize_t), nor the other way around. Typically ssize_t is larger than int, but the safe and portable option in C99 is to use intmax_t instead for the argument and the return value. The only guarantees you have wrt. the relationship between int and ssize_t are: int can store values of at least the range [-2^15 … … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)