What is a "set" in C++? When are they useful?
I'm having a hard time conceptualizing c++ sets, actually sets in general. What are they? How are they useful? ...
I'm having a hard time conceptualizing c++ sets, actually sets in general. What are they? How are they useful? ...
Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int x, int y) : x(x), y(y) {} int x, y; }; class B { public: operator A() { return A(x,y); } float x, y; }; void func1(A a) { cout << "(" << a.x << "," << a.y << ")" << endl; } void func2(A *a, int len) { ...
Consider this example: #include <iostream> class myclass { public: void print() { std::cout << "myclass"; } }; int main() { myclass* p = 0x0; // any address p->print(); // prints "myclass" } I didn't call the member function print through an object of type myclass. Instead I called it from a pointer to a random place in...
Hello, I have a program that links in zlib v1.2.3 and it got the following error: deflateEnd error 'no msg' kind: 'Z_DATA_ERROR': -3 The program has work successfully with lots of different files to be compressed. Does anyone know what the 'no msg' of kind Z_DATA_ERROR means and how one would go about debugging it? Thanks. -Willia...
Hello, What is a good way to call 'uname -a' from a C++ program and send the results to a stream? I looked at system() and exec(), but they do not seem to give access to the stdout of the call. Thanks. -William ...
I have the following code which ends up forever reading '/proc/cpuinfo' as it keeps getting the same result every read. Why doesn't the file pointer get advanced and reach eof ever? Seems this special file has different semantics. const int bufSize = 4096; char buf[bufSize + 1]; const string cpuInfo = "/proc/cpuinfo"; int cpuF...
Hokay so I have an application where I need some IPC... I'm thinking named pipes are the way to go because they are so easy to use. Anyways, I have a question about how to handle dynamic memory using named pipes. Say I have a class such as this: class MyTestClass { public: MyTestClass() { _data = new int(4); } int GetData(...
Sometimes it necessary to compary a string's length with a constant. For example: if ( line.length() > 2 ) { // Do something... } But I trying to avoid using "magic" constants in code. Usually I use such code: if ( line.length() > strlen("[]") ) { // Do something... } It more readable, but not efficient because of function ca...
Just to experiment assembly in C++, I tried the following, which is causing the application to crash: int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { __asm { push 5000 call Sleep } ... } the ass...
Hi, Is there an easy way to indent the output going to an ofstream object? I have a C++ character array that is null terminate and includes newlines. I'd like to output this to the stream but indent each line with two spaces. Is there an easy way to do this with the stream manipulators like you can change the base for integer output ...
Possible duplicate What is the best open source example of a lightweight Windows Application? µTorrent is a small bit-torrent client, a really small one. It doesn't come with an installer, just a exe, you drop in your PATH somewhere. It's super lightweight and yet feature rich. Plus it is the work of one man. It's also close...
I am looking for a bit of clarification on how the algorithms implemented in Canny edge detection - Wikipedia entry - work. It seems pretty straightforward to perform noise reduction using a 2D Gaussian filter, but I have heard that using two 1D filters - how is this accomplished? It's also simple to calculate the gradient and edge dir...
Hi, After trying many and searching web option to compile and load dll I could not able to create dll for tcl. Can you explain me how to do this. ...
Hi All, I have developed a win32 application using c/c++, which runs on vista and xp, I wanted to know, can i get any event in my application when my application is killed from task manager, by selecting the "end process" button I want to free some memory on exit of my application. Please help in this regard with regards, Vinayak...
The following code #include <iostream> using namespace std; int main() { const char* const foo = "f"; const char bar[] = "b"; cout << "sizeof(string literal) = " << sizeof( "f" ) << endl; cout << "sizeof(const char* const) = " << sizeof( foo ) << endl; cout << "sizeof(const char[]) = " << sizeof( bar ) << endl; ...
Hello, we have a huge codebase with about 1000k lines of native/unmanaged legacy c++ - code and we are going to provide the code with unit tests and MSTest would fit perfectly in our current development environment (TFS, VS 2010, ...). I know that MSTest is orginally meant to test managed code but its also possible to write unit tests ...
I've been reading about Singleton pattern for last few days. The general perception is that the scenarios where it is required are quite few (if not rare) probably because it has its own set of problems such as In a garbage collection environment it can be an issue with regards to memory management. In a multithreaded environment it ca...
I've distilled an equation down to this: speed = ( ( rear_wheel_speed_a + front_wheel_speed_a ) << 10 ) + ( ( rear_wheel_speed_b + front_wheel_speed_b ) << 2 ); but for some reason I'm getting unexpected results so I must be doing something wrong. This started out like this: speed = ((((rear_wheel_speed_a * 256 + rear_wheel_s...
Hello, I'm essentially trying to make a DNS proxy application using Qt4. If I set my DNS nameserver to 'localhost' then I want to forward all DNS requests to the server specified in the remoteSocket object. Everything seems to be working fine except sending the data from the remoteSocket object back to the localSocket object which is ...
I'm well aware that in C++ int someValue = i++; array[i++] = otherValue; has different effect compared to int someValue = ++i; array[++i] = otherValue; but every once in a while I see statements with prefix increment in for-loops or just by their own: for( int i = 0; i < count; ++i ) { //do stuff } or for( int i = 0; i < ...