c++

Is it bad that C++0x's lambda expressions don't have a named type?

I've been reading a bit about lambda expressions on the internet recently and it seems to me that C++0x's lambda expressions will not have a single type (or types) that will bind exclusively to lambda expressions -- in other words, lambda expressions will only match template arguments or auto arguments/variables. What happens, as describ...

Performance issues with hard disk reading

I have a C++ program which reads files from the hard disk and does some processing on the data in the files. I am using standard Win32 APIs to read the files. My problem is that this program is blazingly fast some times and then suddenly slows down to 1/6th of the previous speed. If I read the same files again and again over multiple run...

Memory corrupt in adding string to vector<string> loop

This is on Visual Studio 2008 on a dual-core, 32 bit Vista machine. In the debug code this runs fine, but in Release mode this bombs: void getFromDB(vector<string>& dates) { ... sql::Resultset res = stmt->executeQuery("SELECT FROM ..."); while (res->next()) { string date = res->getString("date"); dates.push_bac...

Setting the internal buffer used by a standard stream (pubsetbuf)

I'm writing a subroutine that needs to write data to an existing buffer, and I would like to use the stringstream class to facilitate the formatting of the data. Initially, I used the following code to copy the contents of the stream into the buffer, but would like to avoid this solution as it copies too much data. #include <sstream> #...

Monitioring running application

Hi! I want to monitor all running applications, get events of application main window or child windows. How can I do it? ...

How to get a timestamp older than 1901

I'm trying to find to accurately count the number of seconds since Jan 1, 1850 to the present in a couple of languages (JavaScript, C++, and Python [don't even ask, I stopped asking these questions long ago]). Problem is the platforms store timestamps as 32-bit signed integers, so I can't get a timestamp for dates older than 1901 to eas...

What's the best way to discover why threads are being created in my C++ app and what they do?

I am doing an audit of a C++ app running on Windows, compiled against multithreaded debug DLL. It has a lot of third party dependencies which can spawn threads. I need to track why each thread is there and how much stack space it is allocating. What is a good way to trace back to the start of a thread's creation so I can see where it ...

End of File in C++

Hi, I have a n X 2 matrix stored in a text file as it is. I try to read it in C++ nb_try=0; fin>>c_tmp>>gamma_tmp; while (!fin.eof( )) //if not at end of file, continue reading numbers { // store cs_bit.push_back(c_tmp); gammas_bit.push_back(gamma_tmp); nb_try++; // read fin>>c_tmp; assert(!fin.fail( )); // fail at ...

How do I Search/Find and Replace in an STL string

Is there a way to replace all occurrences of a substring with another string in std::string? For instance: void SomeFunction(std::string& str) { str = str.replace("hello", "world"); //< I'm looking for something nice like this } ...

Undefined symbol _main when trying to build shared library g++ / mac

I am trying to build libdecodeqr on a mac. My c++ building and linking history is all on windows, so it's an exciting journey of discovery. I have finally got to the point where I want to create the linked library. The command I am running is: g++ -shared -o libdecodeqr.so.0.9.3 bitstream.o codedata.o container.o ecidecoder.o formati...

How To Prepare An ActiveX Control For Delivery Over The Web

So i have the misfortune of embedding this proprietary ActiveX control we created into a web page so that it downloads the code from our server and installs as necessary. Our ActiveX requires a host of other files which need to be installed along with the activex control itself. It should also be noted that the activex and all its de...

C++ HashTable Object implementation

int hazmat::hashStr(char const * const str) { int count = 0; for ( unsigned i = 0; i < strlen( str ); i++ ) { count += str[i]; // get the ascii sum. } return count % maxSize; } ...

Simple C/C++ network I/O library

I have the following problem to solve. I want to make a number of requests to a number of "remote" servers (actually, a server farm we control). The connection is very simple. Send a line, and then read lines back. Because of the number of requests and the number of servers, I use pthreads, one for each request. The naive approach, ...

c++ std vector - invalidated iterator question

I have a standard vector of pointers. Under what circumstances might an iterator into this vector become invalidated? I have reason to believe that when an object is deleted, any vector iterator referencing it is thereby invalidated. This does not seem correct to me, however. I do believe this would be the standard behavior of containe...

accessing class object types C++

How can i access class obect types in a statically declared private member function?: class Y { .. private: friend class X; X *myX; }; class X { public: friend class Y; private: static int foo( const char * const key ); Y *myX; }; int X::foo( const char * const key ) { X *myX = NULL; // illegal. } static c...

What is the scope of a namespace alias in C++?

Does a C++ namespace alias defined inside a function definition have a block, function, file, or other scope (duration of validity)? ...

Using pseudo tty with ssh results in warning

I am using ssh from my application and must pass "-t -t" to ssh in order for it to work correctly. Otherwise, the stdin of my application is interfered with by the call to ssh. Forcing a pseudo terminal to ssh via the -t -t avoids this issue, but instead results in the following obscure error message coming back from ssh, although the ...

Lambda Expressions and Script Parsing -- Is this a good design idea?

Hello all, I've written a handful of basic 2D shooter games, and they work great, as far as they go. To build upon my programming knowledge, I've decided that I would like to extend my game using a simple scripting language to control some objects. The purpose is more about the general process of design of writing a script parser / exec...

c++ how to add a zero bits byte or null to a string

Hi I am doing a simple client implementation of TFTP. Here i need to send read request in following format /* send request 2 bytes string 1 byte string 1 byte ------------------------------------------------------ RRQ/ | 01/02 | Filename | 0 | Mode | 0 | WRQ -----------------------------------------...

QTabWidget tab context menu

I need to display a context menu whenever a tab is clicked on and it needs to react to that specific tab. Is there any way to do this without subclassing it? ...