598 Answered Questions for the topic C++
C++
08/14/19
How can I convert a std::string to int?
Just have a quick question. I've looked around the internet quite a bit and I've found a few solutions but none of them have worked yet. Looking at converting a string to an int and I don't mean...
more
C++
08/12/19
What is a smart pointer and when should I use one?
What is a smart pointer and when should I use one?
C++
08/12/19
How do I output coloured text to a Linux terminal?
How do I print coloured characters to a Linux terminal that supports it?
How do I tell whether the terminal supports colour codes?
C++
08/11/19
What is the lifetime of a static variable in a C++ function?
If a variable is declared as `static` in a function's scope it is only initialized once and retains its value between function calls. What exactly is its lifetime? When do its constructor and...
more
C++
08/10/19
When you should use virtual inheritance?
C++
08/09/19
Why does C++ compilation take so long?
Compiling a C++ file takes a very long time when compared to C# and Java. It takes significantly longer to compile a C++ file than it would to run a normal size Python script. I'm currently using...
more
C++
08/07/19
How to convert a std::string to const char* or char*?
How can I convert an `std::string` to a `char*` or a `const char*`?
C++
08/07/19
How do malloc() and free() work?
I want to know how `malloc` and `free` work.
int main() {
unsigned char *p = (unsigned char*)malloc(4*sizeof(unsigned char));
memset(p,0,4);
strcpy((char*)p,"abcdabcd"); //...
more
C++
08/07/19
What is external linkage and internal linkage?
I want to understand the external linkage and internal linkage and their difference.
I also want to know the meaning of
> `const` variables internally link by default unless otherwise...
more
C++
08/06/19
Why does the order in which libraries are linked sometimes cause errors in GCC?
Why does the order in which libraries are linked sometimes cause errors in GCC?
C++
08/05/19
What is the meaning of prepended double colon "::"?
I found this line of a code in a class which I have to modify:
::Configuration * tmpCo = m_configurationDB;//pointer to current db
and I don't know what exactly means the double colon prepended...
more
C++
08/04/19
Advantages of using forward?
In perfect forwarding, `std::forward` is used to convert the named rvalue references `t1` and `t2` to unnamed rvalue references. What is the purpose of doing that? How would that affect the called...
more
C++
08/04/19
How to convert vector to array?
How do I convert a `std::vector<double>` to a `double array[]`?
C++
08/03/19
Difference between static and shared libraries?
What is the difference between static and shared libraries?
I use Eclipse and there are several project types including Static Libraries and Shared Libraries? Does one have an advantage over the...
more
C++
08/02/19
What are the barriers to understanding pointers and what can be done to overcome them?
Why are pointers such a leading factor of confusion for many new, and even old, college level students in C or C++? Are there any tools or thought processes that helped you understand how pointers...
more
C++
07/31/19
What is the difference between const int*, const int * const, and int const *?
I always mess up how to use `const int*`, `const int * const`, and `int const *` correctly. Is there a set of rules defining what you can and cannot do?
I want to know all the do's and all don'ts...
more
C++
07/30/19
What is the difference between the dot (.) operator and -> in C++?
What is the difference between the dot (.) operator and -> in C++?
C++
07/30/19
Why does changing 0.1f to 0 slow down performance by 10x?
Why does this bit of code,
const float x[16] = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8,
1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6};
const float z[16] = {1.123,...
more
C++
07/30/19
How do I execute a command and get output of command within C++ using POSIX?
I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example...
more
C++
07/29/19
Pointer vs. Reference?
What would be better practice when giving a function the original variable to work with:
unsigned long x = 4;
void func1(unsigned long& val) {
val = 5;
}
func1(x);
or:
...
more
C++
07/28/19
Initialization of a normal array with one default value?
[C++ Notes: Array Initialization](http://www.fredosaurus.com/notes-cpp/arrayptr/array-initialization.html) has a nice list over initialization of arrays. I have a int array[100] = {-1};expecting...
more
C++
07/28/19
How to check that an element is in a std::set?
How do you check that an element is in a set?
Is there a simpler equivalent of the following code:
myset.find(x) != myset.end()
C++
07/27/19
When to use extern in C++?
I'm reading "Think in C++" and it just introduced the `extern` declaration. For example:
extern int x;
extern float y;
I think I understand the meaning (declaration without definition), but...
more
C++
07/27/19
What do single quotes do in C++ when used on multiple characters?
I'm curious about this code:
cout << 'test'; // Note the single quotes.
gives me an output of `1952805748`.
My question: Is the output an address in memory or something?
C++
07/27/19
Why use apparently meaningless do-while and if-else statements in macros?
In many C/C++ macros I'm seeing the code of the macro wrapped in what seems like a meaningless `do while` loop. Here are examples.
#define FOO(X) do { f(X); g(X); } while (0)
#define FOO(X) if...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.