c++

Is modifying a file without writing a new file possible in c++?

Let's say I have a text file that is 100 lines long. I want to only change what is in the 50th line. One way to do it is open the file for input and open a new file for output. Use a for-loop to read in the first half of the file line by line and write to the second file line by line, then write what I want to change, and then write o...

funny looking comments - c++

when i read through source files of opensource projects i often come across some weird phrases in the comments /* @brief ...... @usage..... @remarks.... @par.... */ questions 1.What are they?(were not mentioned when i was learning c++) 2.Do they have any documentation(where) ...

Why won't gcc compile a class declaration as a reference argument?

This compiles fine in Visual studio, but why not in XCode? class A() {}; someMethod(A& a); someMethod(A()); //error: no matching function call in XCode only :( Is this bad form? it seems annoying to have to write the following every time: A a; someMethod(a); //successful compile on Xcode Am i missing something? I am not very...

Multiple variables in switch statement in c

How to write following statement in c using switch statement in c int i = 10; int j = 20; if (i == 10 && j == 20) { Mymethod(); } else if (i == 100 && j == 200) { Yourmethod(); } else if (i == 1000 || j == 2000) // OR { Anymethod(); } EDIT: I have changed the last case from '...

(C++) using a method of an abstract class

is it possible to use a method of an abstract class? how can i use a method of a class without having an instance? ...

How to read in space-delimited information from a file in c++

In a text file I will have a line containing a series of numbers, with each number separated by a space. How would I read each of these numbers and store all of them in an array? ...

issue with std::advance on std::sets

I've stumbled upon what I believe is a bug in the stl algorithm advance. When I'm advancing the iterator off of the end of the container, I get inconsistent results. Sometimes I get container.end(), sometimes I get the last element. I've illustrated this with the following code: #include <algorithm> #include <cstdio> #include <set> ...

Problem with displaying graphs on a Qt canvas

Let's say I'm a Qt newbie. I want a good Qt library for displaying simple graphs. I've found the quanava library. But there is a problem. When I compiled a basic example it looks like graph edges are not painted properly when moving nodes. I don't have any idea where is a bug but this code seems to be rather simple. I think this is a pro...

BN_hex2bn magically segfaults in openSSL

Greetings, this is my first post on stackoverflow, and i'm sorry if its a bit long. I'm trying to build a handshake protocol for my own project and am having issues with the server converting the clients RSA's public key to a Bignum. It works in my clent code, but the server segfaults when attempting to convert the hex value of the clie...

Calling a constructor to reinitialize variables doesn't seem to work?

I wanted to run 1,000 iterations of a program, so set a counter for 1000 in main. I needed to reinitialize various variables after each iteration, and since the class constructor had all the initializations already written out - I decided to call that after each iteration, with the result of each iteration being stored in a variable in ...

Deriving a class from an abstract class (C++)

I have an abstract class with a pure virtual function f() and i want to create a class inherited from that class, and also override function f(). I seperated the header file and the cpp file. I declared the function f(int) in the header file and the definition is in the cpp file. However, the compiler says the derived class is still abst...

gcc precompiled headers weird behaviour with -c option

Short story: I can't make precompiled headers work properly with gcc -c option. Long story: Folks, I'm using gcc-4.4.1 on Linux and before trying precompiled headers in a really large project I decided to test them on simple program. They "kinda work" but I'm not happy with results and I'm sure there is something wrong about my setup....

Custom http service responds fine to local IP address but NOT to localhost or 127.0.0.1

I'm trying to connect to a custom http service written by another developer. The service responds fine on a local IP address and port number. Such as: http://10.1.1.1:1234 but it does NOT respond to http://localhost:1234 or http://127.0.0.1:1234 The service is a simple single function application written in VC++ that takes an http pos...

C++ whats the difference between uint64 and *uint64?

Hey there. Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have a value of 7004431430466964258 p.s. dont worry about the type cast, I am interested why the second * increases the value. Thanks ...

virtual methods and template classes

Hi I got over a problem, I think a very specific one. I've got 2 classes, a B aseclass and a D erived class (from B aseclass). B is a template class ( or class template) and has a pure virtual method virtual void work(const T &dummy) = 0; The D erived class is supposed to reimplement this, but as D is Derived from B rather than D bein...

How do I get the trackbar value?

I feel a little silly asking this, seems pretty simple but I can't find the solution anywhere. I have a trackbar made in visual studio 2008 and I want to use it to adjust an image threshold but I can't find the code to retrieve the sliders/markers position. Any help would be much appreciated and I am using C++ ...

How do I change the class of an object to a subclass of its current class in C++?

I have an array of pointers to a base class, so that I can make those pointers point to (different) subclasses of the base class, but still interact with them. (really only a couple of methods which I made virtual and overloaded) I'm wondering if I can avoid using the pointers, and instead just make an array of the base class, but have ...

Do condition variables still need a mutex if you're changing the checked value atomically?

Here is the typical way to use a condition variable: // The reader(s) lock(some_mutex); if(protected_by_mutex_var != desired_value) some_condition.wait(some_mutex); unlock(some_mutex); // The writer lock(some_mutex); protected_by_mutex_var = desired_value; unlock(some_mutex); some_condition.notify_all(); But if protected_by_mutex...

Can someone explain this "endian-ness" function for me?

Write a program to determine whether a computer is big-endian or little-endian. bool endianness() { int i = 1; char *ptr; ptr = (char*) &i; return (*ptr); } So I have the above function. I don't really get it. ptr = (char*) &i, which I think means a pointer to a character at address of where i is sitting, so if an...

C/C++ Allegro program causes Windows 7 to switch to Aero Basic

Hi SO, I'm just trying out the allegro library, and here is the code which I've got so far: #include <allegro.h> int main(int argc, char *argv[]) { allegro_init(); // initialize the allegro libraries install_keyboard(); // initialize keyboard functions set_color_depth(16); // set the color depth set_gfx_mode(GFX_AUTO...