c++

C++ how to store integer into a binary file??

i gt a struct with 2 integer, i want to store them in a binary file and read it again... here is my code... static const char *ADMIN_FILE = "admin.bin"; struct pw { int a; int b; }; void main(){ pw* p = new pw(); pw* q = new pw(); std::ofstream fout(ADMIN_FILE, ios_base::out | ios_base::binary | ios_base::trunc); std::ifst...

Modifying a const through a non-const pointer

I'm a bit confused what happened in the following code: const int e = 2; int* w = ( int* ) // (1) cast to remove const-ness *w = 5; // (2) cout // (3) outputs 5 cout // (4) outputs 2 cout // (5) w points to the address of e cout In (1), w points to the address of e. In...

how to separate debug and release mode code

During debug mode or while I am doing testing, I need to print lots of various information, so i use this method: #ifdef TESTING // code with lots of debugging info #else // clean code only #endif // TESTING` Is this a good method, or is there any other simple and elegant method ? But this way, I am repeating the same code in two pla...

C++ printf: newline (\n) from commandline argument

How print format string passed as argument ? example.cpp: #include <iostream> int main(int ac, char* av[]) { printf(av[1],"anything"); return 0; } try: example.exe "print this\non newline" output is: print this\non newline instead I want: print this on newline ...

static library visual studio 2008

Hello, I am trying to create a static library of my own. I am however using a third party static lib as well. Now, in my static library I have a .h file which has the client's API in it. All the implementation details are in the .cpp file. No issues there. But, some of my functions in the .cpp file rely on this third party lib. I can...

Anyone knows a matplotlib equivalent in C or C++

I've been using matplotlib in a Python project. It is great. I have now to plot data in a C++ project. Is anyone aware of a plotting library in C or C++? Note that I cannot accept GPL licensed libraries. ...

[C++/Boost] "Unhandled exception" error when using a loop inside thread

Hello there, I got this error Unhandled exception at 0x0049b946 in Program.exe: 0xC0000005: Access violation reading location 0x00000090. and the error points to this line: // thread.hpp ln 56 void run() { f(); // here << } When trying to run this code: void frameFunc() { for(;;) ...

How to use std::allocator in my own container class

I am trying to write a container class which uses STL allocators. What I currently do is to have a private member std::allocator<T> alloc_; (this will later be templated so that the user can pick a different allocator) and then call T* ptr = alloc_.allocate(1,0); to get a pointer to a newly allocated 'T' object (and used alloc_.con...

Hundreds of errors when debuging an open source project(sphinx)

To name a few: `__debugbreak' was not declared in this scope sphinx.cpp /sp/src line 146 C/C++ Problem `__rdtsc' was not declared in this scope sphinx.cpp /sp/src line 452 C/C++ Problem `__stat64' does not name a type sphinx.cpp /sp/src line 15963 C/C++ Problem Are you familiar with the error info?Is there something I...

Why using namespace std is necessary here?

#include <iostream> using namespace std; int main() { cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0; } If I remove the 2nd statement,the build will fail. Why is it necessary? ...

breakdown c++ code size

I'm looking for a nice stackoverflow-style answer to the first question in this old blog post, which I'll repeat below: "I’d really like some tool (ideally, g++ based) that shows me what parts of compiled/linked code are generated from what parts of C++ source code. For instance, to see whether a particular template is being instantiate...

An array problem in C++

To access the array indice at the xth position we can use some sort of illustration as shown below #include<iostream> using namespace std; int main(){ float i[20]; for(int j=0;j<=20;j++) i[j]=0; } However the following piece of code does not work #include<iostream> using namespace std; float oldrand[55]; int jrand; ...

Syntax error in Singleton Template class when porting from linux to windows

I have a singleton library from a linux project that I'm trying to port to Windows. When I try to compile, it errors with syntax error: identifier "rpSingleton" The error is from the following section of code: template <typename T> inline T& Q::Singleton<T>::Instance() { Singleton<T>*& rp_singleton(rpSingleton()); //ERRORS...

how to compile boost thread library

Hi, I want to compile only the thread and regular expresession library of boost and I want both static and dynamic libs. Could you please let us know how to do that? Thanks. ...

Connect to an elevated COM server from a non-elevated process

We have a program which launches a child process that hosts a local COM server, which for various reasons must be launched elevated. Everything works fine so long as both the parent and the child process are elevated. However, we also want to run when the parent process is non-elevated. Launching the child process results in a UAC dialo...

Cannot find sleep function

hello, i'm new at C Programming (i learned c++) i want to create a process with windows.h at first i just want to start my main programm that creates a process ( --> starts an other programm) that's my code, but it doesn't really work, i removed every unnessasery line of code but "void sleep(700)" (or "sleep (700)" for testing if the w...

When to write an iterator?

I know this is probably a silly question.. When would I need to write my own iterator? Is it just when designing my own container class? Are there any other times when I would want to create my own iterator? Examples would be appropriated. -Jon ...

How to monitor a directory for files in C++?

I need to monitor a directory which contains many files and a process reads and deletes the .txt files from the directory; once all the .txt files are consumed, the consuming process needs to be killed. How do I check if all the .txt files are consumed using C++? I am developing my application on Visual Studio on windows platform. ...

Not catching all mouse events with wxWidgets

Hi I am am trying to catch mouse movements for a MouseOver function in an app created with Code::Blocks using the wxSmith plugin. I have stumbled upon a puzzling problem. EVT_MOUSEWHEEL calling the function in the EventTable works well, but all other macros have no result at all. And the mousewheel is not really want I want (I just ...

Exactly How Does My C++ Program Terminate When it Runs Out of Memory?

The following C++ program crashes on my Windows XP machine with a message "Abnormal program termination" class Thing {}; int main() { for (;;) new Thing(); } I would say it's an out of memory problem, except I'm not sure Windows gets near the limit. Is it Windows killing it on purpose? If so, how does it decide? ...