How do you reverse a string in place in C or C++?
How do you reverse a string in C or C++ without requiring a separate buffer to hold the reversed string? 20 Answers 20
How do you reverse a string in C or C++ without requiring a separate buffer to hold the reversed string? 20 Answers 20
Why does this: #include <string> #include <iostream> using namespace std; class Sandbox { public: Sandbox(const string& n) : member(n) {} const string& member; }; int main() { Sandbox sandbox(string(“four”)); cout << “The answer is: ” << sandbox.member << endl; return 0; } Give output of: The answer is: Instead of: The answer is: four 6 … Read more
I successfully implemented the OpenCV square-detection example in my test application, but now need to filter the output, because it’s quite messy – or is my code wrong? I’m interested in the four corner points of the paper for skew reduction (like that) and further processing … Input & Output: Original image: click Code: double angle( … Read more
What I mean is – we know that the std::map‘s elements are sorted according to the keys. So, let’s say the keys are integers. If I iterate from std::map::begin() to std::map::end() using a for, does the standard guarantee that I’ll iterate consequently through the elements with keys, sorted in ascending order? Example: std::map<int, int> map_; … Read more
Consider the following piece of code: #include <stdio.h> #include <sys/types.h> #include <unistd.h> int main(void) { int i; for(i = 0; i < 2; i++) { fork(); printf(“.”); } return 0; } This program outputs 8 dots. How can that be possible? Should not there be 6 dots instead? 3 Answers 3
I came across the following code: template <typename T, typename T1> auto compose(T a, T1 b) -> decltype(a + b) { return a+b; } There is one thing I cannot understand: Where could I find out what the arrow operator (->) means in the function heading? I guess purely logically, that the -> operator determines … Read more
Quick question: what is the compiler flag to allow g++ to spawn multiple instances of itself in order to compile large projects quicker (for example 4 source files at a time for a multi-core CPU)? 8 Answers 8
Are there any advantages of std::for_each over for loop? To me, std::for_each only seems to hinder the readability of code. Why do then some coding standards recommend its use? 22 Answers 22
How does the comma operator work in C++? For instance, if I do: a = b, c; Does a end up equaling b or c? (Yes, I know this is easy to test – just documenting on here for someone to find the answer quickly.) Update: This question has exposed a nuance when using the … Read more
This question already has answers here: Why can templates only be implemented in the header file? (17 answers) Closed 7 years ago. I have no idea why this is happenning, since I think I have everything properly declared and defined. I have the following program, designed with templates. It’s a simple implementation of a queue, … Read more