What is `CString`?

CString is neither a C nor a C++ type. It appears to be a Microsoft invention that is essentially an alternative to std::string: CString objects can grow as a result of concatenation operations. CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string. You can freely substitute CString objects for const char* and LPCTSTR function arguments. A conversion … Read more

When to use extern “C” in simple words? [duplicate]

You need to use extern “C” in C++ when declaring a function that was implemented/compiled in C. The use of extern “C” tells the compiler/linker to use the C naming and calling conventions, instead of the C++ name mangling and C++ calling conventions that would be used otherwise. For functions provided by other libraries, you will almost never need … Read more

What is meant by Resource Acquisition is Initialization (RAII)?

It’s a really terrible name for an incredibly powerful concept, and perhaps one of the number 1 things that C++ developers miss when they switch to other languages. There has been a bit of a movement to try to rename this concept as Scope-Bound Resource Management, though it doesn’t seem to have caught on just yet. … Read more

Conversion from string to char – c++

You can get a specific character from a string simply by indexing it. For example, the fifth character of str is str[4] (off by one since the first character is str[0]). Keep in mind you’ll run into problems if the string is shorter than your index thinks it is. c_str(), as you have in your comments, gives you a char* representation (the … Read more

How to throw a C++ exception

Simple: The Standard Library comes with a nice collection of built-in exception objects you can throw. Keep in mind that you should always throw by value and catch by reference: You can have multiple catch() statements after each try, so you can handle different exception types separately if you want. You can also re-throw exceptions: And to … Read more

What exactly is the difference between “pass by reference” in C and in C++?

There are questions that already deal with the difference between passing by reference and passing by value. In essence, passing an argument by value to a function means that the function will have its own copy of the argument – its value is copied. Modifying that copy will not modify the original object. However, when passing by reference, … Read more

g++ ld: symbol(s) not found for architecture x86_64

I had a similar warning/error/failure when I was simply trying to make an executable from two different object files (main.o and add.o). I was using the command: gcc -o exec main.o add.o But my program is a C++ program. Using the g++ compiler solved my issue: g++ -o exec main.o add.o I was always under the impression … Read more

Why are #ifndef and #define used in C++ header files?

Those are called #include guards. Once the header is included, it checks if a unique value (in this case HEADERFILE_H) is defined. Then if it’s not defined, it defines it and continues to the rest of the page. When the code is included again, the first ifndef fails, resulting in a blank file. That prevents … Read more

C++ string to double conversion

You can convert char to int and viceversa easily because for the machine an int and a char are the same, 8 bits, the only difference comes when they have to be shown in screen, if the number is 65 and is saved as a char, then it will show ‘A’, if it’s saved as … Read more

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