586 Answered Questions for the topic C++
06/26/19
Searching an Array for an Exact Match in C++
Ensure the provided code file named MichiganCities.cpp is open.
Study the prewritten code to make sure you understand it.
Write a loop statement that examines the names of cities stored in the...
more
Digit-increasing number test?
A number is called digit-increasing if it is equal n + nn + nnn + ... for some digit n between 1 and 9. For example 24 is digit-increasing because it equals 2 + 22 (here n = 2).
Actually, a friend...
more
C++
06/25/19
Is it possible to print a variable's type in standard C++?
For example:
int a = 12;
cout << typeof(a) << endl;
Expected output:
int
C++
06/25/19
Difference between `constexpr` and `const`?
What's the difference between `constexpr` and `const`?
- When can I use only one of them?
- When can I use both and how should I choose one?
C++
06/22/19
Meaning of 'const' last in a function declaration of a class?
What is the meaning of `const` in declarations like these? The `const` confuses me.
class foobar
{
public:
operator int () const;
const char* foo() const;
};
06/21/19
Can we implement a doubly-linked list using a single pointer?
I want to use a structure like:
struct node {
char[10] tag;
struct node *next;
};
I want to use the above structure to create a doubly-linked list. Is that possible and if yes, then how I can...
more
C++
06/21/19
std::wstring VS std::string?
I am not able to understand the differences between `std::string` and `std::wstring`. I know `wstring` supports wide characters such as Unicode characters. I have got the following questions:
1....
more
C++
06/19/19
Fastest way to check if a file exist using standard C++/C++11/C?
I would like to find the fastest way to check if a file exist in standard C++11, C++, or C. I have thousands of files and before doing something on them I need to check if all of them exist. What...
more
C++
06/18/19
Is < faster than <=?
I'm reading a book where the author says that `if( a < 901 )` is faster than `if( a <= 900 )`.
Not exactly as in this simple example, but there are slight performance changes on loop...
more
C++
06/16/19
What does int argc, char *argv[] mean?
In many C++ IDE's and compilers, when it generates the main function for you, it looks like this:
int main(int argc, char *argv[])
When I code C++ without an IDE, just with a command line...
more
C++
06/16/19
Sleep for milliseconds?
I know the POSIX `sleep(x)` function makes the program sleep for x seconds. Is there a function to make the program sleep for x *milliseconds* in C++?
C++
06/11/19
How to initialize private static members in C++?
What is the best way to initialize a private, static data member in C++? I tried this in my header file, but it gives me weird linker errors:
class foo
{
private:
static int i;
...
more
C++
06/09/19
How to implement the factory method pattern in C++ correctly?
There's this one thing in C++ which has been making me feel uncomfortable for quite a long time, because I honestly don't know how to do it, even though it sounds simple:
**How do I implement...
more
C++
06/09/19
What is a segmentation fault?
What is a segmentation fault? Is it different in C and C++? How are segmentation faults and dangling pointers related?
C++
06/08/19
Do I need to explicitly call the base virtual destructor?
When overriding a class in C++ (with a virtual destructor) I am implementing the destructor again as virtual on the inheriting class, but do I need to call the base destructor?
If so I imagine...
more
C++
06/02/19
How would I get access of a variable in a namespace in c++?
For example:
namespace space1{
int var;
namespace space2{
int var;
namespace space3{
int var;
}
}
How would I access the variable from space1...
more
C++
05/31/19
What's the purpose of using braces (i.e. {}) for a single-line if or loop?
I'm reading some lecture notes of my C++ lecturer and he wrote the following:
> 1. Use Indentation // OK
> 2. Never rely on operator precedence - Always use parentheses // OK
> 3....
more
C++
05/31/19
How do you get assembler output from C/C++ source in gcc?
How does one do this?
If I want to analyze how something is getting compiled, how would I get the emitted assembly code?
C++
05/30/19
C++ code file extension? .cc vs .cpp?
I have seen C++ code saved as both `.cc` and `.cpp` files. Is there a difference between the two?
I am mainly concerned with programs on Linux systems.
05/29/19
Is there a Java equivalent or methodology for the typedef keyword in C++?
Coming from a C and C++ background, I found judicious use of **`typedef`** to be incredibly helpful. Do you know of a way to achieve similar functionality in Java, whether that be a Java...
more
Is D a credible alternative to Java and C++?
Is the [D language](http://www.digitalmars.com/d/) a credible alternative to Java and C++? What will it take to become a credible alternative? Should I bother learning it? Does it deserve...
more
05/28/19
Why are C++ inline functions in the header?
<sub>NB This is not a question about how to use inline functions or how they work, more why they are done the way they are.</sub>The declaration of a class member function does not need...
more
05/28/19
What is a scalar Object in C++?
usr/bin/ld: cannot find -l<nameOfTheLibrary>?
I'm trying to compile my program and it returns this error :
usr/bin/ld: cannot find -l<nameOfTheLibrary>
in my makefile I use the command `g++` and link to my library which is a symbolic...
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.