c++

Everything inside < > lost, not seen in html ?

I have many source/text file, say file.cpp or file.txt . Now, I want to see all my code/text in browser, so that it will be easy for me to navigate many files. My main motive for doing all this is, I am learning C++ myself, so whenever I learn something new, I create some sample code and then compile and run it. Also, along these codes...

When using boost::program_options, how does one set the name of the argument?

When using boost::program_options, how do I set the name of an argument for boost::program_options::value<>()? #include <iostream> #include <boost/program_options.hpp> int main() { boost::program_options::options_description desc; desc.add_options() ("width", boost::program_options::value<int>(), "Give width"); std::co...

Is there an elegant way to bridge two devices/streams in ASIO?

Given two stream-oriented I/O objects in Asio, what is the simplest way to forward data from one device to the other in both directions? Could this be done with boost::iostreams::combination or boost::iostreams:copy perhaps? Or is a manual approach better--waiting for data on each end and then writing it out to the other stream? In other...

Templated copy-constructor fails with specific templated type

As some of my code required implicit conversion between matrices of different types (e.g. Matrix<int> to Matrix<double>), I defined a templated copy constructor Matrix<T>::Matrix(Matrix<U> const&) instead of the standard Matrix<T>::Matrix(Matrix<T> const&): template <typename T> class Matrix { public: // ... template <typename U...

convert batch files to exes

I'm wondering if it's possible to convert batch files to executables using C++? I have plenty of batch files here and I would like to convert them to executables (mainly to obfuscate the code). I understand that there are 3rd party tools that can do this but I was thinking that this would be a good opportunity for a programming project. ...

How do I pass a struct from an unmanaged C++ program to a C# program?

This is my second post. Here is what I am trying to do: Call an unmanaged c++ program from c#, passing in a array of structs from the c# program and return a updated version of the array of structs from the c++ program. Here is the calling c# program: using System; using System.Runtime.InteropServices; namespace TestCallingC { c...

Using VS2008 with C/C++

I've decided to dive into some code written in C and I'd like to use VS I have VS08 Pro which I'm using now primarily for C#, but I've noticed that there are no options for C in VS. Also I've noticed that although VS has projects, and whatnot for C++ that the build options are all greyed out so I cannot build C++. What do I need to bui...

Optimizing bit array accesses

Hi all, I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: for( int i = 0; i < i...

Limiting Singleton instance to thread.

What is a good way to implement a singleton that will be restricted only to the thread that seeks its instance? Is there a thread id or something that I can use to do that? I'm using Carbon threading API but will have to implement this on windows and pure POSIX later too, so any technique is appreciated. ...

Return value for a << operator function of a custom string class in C++

Hello there, I am trying to create my own std::string wrapper to extend its functionality. But I got a problem when declaring the << operator. Here's my code so far: my custom string class: class MyCustomString : private std::string { public: std::string data; MyCustomString() { data.assign(""); } MyCustomString(char *value) { d...

Does Qt work well with STL & Boost ?

I am interested in learning Qt. I am fairly good with C++, STL and Boost. I like STL/Boost style very much, and I use them with C++ whenever I can in uni projects. However, I always miss the GUI. It seems that Qt is the best solution in my case. Qt does have a good collection of containers, but I am greatly familiar with STL/Boost stuff....

How to unordered_set<tuple<int,int>> ?

I had encountered strange problem while construct a unordeed_set<tuple<int,int>>. I had tried VC++8, gcc3.2, gcc4.3, all have the same result. I have no idea what's wrong with the code, following is my code: #include <boost/unordered_set.hpp> #include <boost/tuple/tuple.hpp> // For unordered container, the declaration of operator== #inc...

generic non-invasive cache wrapper

I'm trying create a class which adds functionality to a generic class, without directly interfacing with the wrapped class. A good example of this would be a smart pointer. Specifically, I'd like to create a wrapper which caches all the i/o for one (or any?) method invoked through the wrapper. Ideally, the cache wrapper have the follo...

sstream question with chars

I have a member function that asks the user for a file name and then gets input from file and uses it on different functions. Each function takes in chars or chars. However its not quite executing the functions. I think it has to do with sstream picking the data out from the file then making them chars? Is it possible to separate the ...

Very poor boost::lexical_cast performance

Hello, Windows XP SP3. Core 2 Duo 2.0 GHz. I'm finding the boost::lexical_cast performance to be extremely slow. Wanted to find out ways to speed up the code. Using /O2 optimizations on visual c++ 2008 and comparing with java 1.6 and python 2.6.2 I see the following results. Integer casting: c++: std::string s ; for(int i = 0; i < 10...

Object pool vs. dynamic allocation

When should one prefer object pool over dynamically allocated objects? I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool? Thanks. ...

Advice : Personal project : garbage collector.. i need a starting point

hello, i've been reading about memory allocation and c++ programming in general.. my boss thinks it is a good idea to try and design a simple garbage collector to enhance my learning ( i always believed.. it is better to code a project, than to do a generalized written code, to test functions, because it helps understand the exact usage ...

Visual studio 2008 folder browser dialog

In visual studio 2008 there is a folder browser dialog that looks like this(very similar to file open dialog): http://img24.imageshack.us/img24/5742/folderbrowser.jpg Does anyone know how to invoke it from code? ...

Boost::Test -- generation of Main()?

Hello :) I'm a bit confused on setting up the boost test library. Here is my code: #include "stdafx.h" #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE pevUnitTest #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE( TesterTest ) { BOOST_CHECK(true); } My compiler generates the wonderfully useful error message: 1>MSVC...

Any comments to this (hopefully) 100% safe double-check-locking replacement for singletons.

As Scott Meyers and Andrei Alexandrescu outlined in this article the simple try to implement the double-check locking implementation is unsafe in C++ specifically and in general on multi-processor systems without using memory barriers. I was thinking a little bit about that and came to a solution that avoids using memory barriers and sh...