c++

How to reverse data using an array of pointers (parse binary file)

Hey I am parsing a binary file using a specification. The file comes in big-endian mode because it has streamed packets accumulated. I have to reverse the length of the packets in order to "reinterpret_cast" them into the right variable type. (I am not able to use net/inet.h function because the packets has different lengths). The read...

Using boost::filesystem with the nuwen.net minGW distro?

I've been working a couple of small c++ projects using the nuwen.net minGW distro and I've run into a problem trying to link against the boost::filesystem library. I am invoking g++ like this: g++ -g -Wall -pedantic -std=c++0x -static-libgcc -o main.exe main.cpp -lmingw32 -lstdc++ -lboost_system -lboost_filesystem However, this result...

boost spirit qi numeric parsing of integer and floating points

Hi, i am trying to make sense of the following result. The test case code is #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/i...

Cross Platform File Exists & Read In C++

Hi How can I write two simple cross platform (Linux, Windows) functions for reading text file, and determine if some file exists? I don't want to use a big library like Boost.IO for that. It's a very small plugin for some software and I don't think it's neccsary. Thanks. ...

C++: Are YOU using Loki or Boost for functors ?

Hi all, I've been reading Alexandrescu's book, Modern C++ design , and I've been quite impressed by the techniques he uses, so I wanted to add Loki library to my application. However, after further investigation, I saw that boost, that I'm already using, provides a lot of similar functionality (not all though, I couldn't find a singl...

How can this compile? (delete a member of const object)

I would expect an error inside the copy constructor, but this compiles just fine with MSVC10. class Test { public: Test() { p = new int(0); } Test(const Test& t) { delete t.p; // I would expect an error here } ~Test() { delete p; } private: int* p; }; ...

private object pointer vs object value, and returning object internals

Related to: http://stackoverflow.com/questions/2625719/c-private-pointer-leaking According to Effective C++ (Item 28), "avoid returning handles (references, pointers, or iterators) to object internals. It increases encapsulation, helps const member functions act const, and minimizes the creation of dangling handles." Returning objects ...

'No matching function' -error when trying to insert to a set (c++)

I have the following code: class asd { public: int b; asd() { b = rand() % 10; } bool operator<(asd &other) { return b < other.b; } }; int main() { asd * c; c = new asd(); set <asd> uaua; uaua.insert(c); } Yet when running it, I get this error: main.cpp|36|error: no matching function for...

Reading a number from file C++

I have a file with a simple number, for example: 66 or 126 How can I read it to a int value in C++? Note that the file may also contain some spaces or enters after the number. I started like so: int ReadNumber() { fstream filestr; filestr.open("number.txt", fstream::in | fstream::app); filestr.close() } How to co...

Unsigned Long Long Won't Go Beyond The 93th Fibonacci Number?

Here's the code I wrote for finding the n-th Fibonacci number: unsigned long long fib(int n) { unsigned long long u = 1, v = 1, t; for(int i=2; i<=n; i++) { t = u + v; u = v; v = t; } return v; } While the algorithm runs pretty quickly, the output starts to freak out when n>93. I think/kno...

sparse_vector template class: How do I clean it up?

I'm not sure if this is a good question or not — please close it if not. I set out to write (using boost::coordinate_vector as a starting point) a sparse_vector template class that efficiently implements a vector-like interface, but is sparse. It implements all the usual vector operations and a fast sparse iterator that iterates over t...

C++ weird syntax spotted in Boost template parameters

I was having a look at the "Function" class documentation in Boost, and stumbled across this: boost::function<float (int x, int y)> f; I must admit this syntax is highly confusing for me. How can this be legal C++ ? Is there any trick under the hood ? Is this syntax documented anywhere? ...

What's the best way to have a variable number of template parameters ?

Please consider this -probably poorly written- example : class Command; class Command : public boost::enable_shared_from_this<Command> { public : void execute() { executeImpl(); // then do some stuff which is common to all commands ... } // Much more stuff ... private: virtual void e...

Getting text from tab control item is failing

I'm trying to get the text from a tab control like this: TCITEM itm; itm.mask = TCIF_TEXT; TabCtrl_GetItem(engineGL.controls.MainGlTab.MainTabHwnd,i,&itm); but the psztext part of the structure is returning a bad pointer (0xcccccccccc). I create the tabs like this: void OGLMAINTAB::AddTab( char *name ) { TCITEM ...

Linker issue calling the D3DX10CreateEffectFromFile() method

Having issues trying to retrieve a effect file for directX. If I do not include the D3DX10CreateEffectFromFile() method, the application compiles correctly. If I do include it. I get the following error 1>GXDX.obj : error LNK2019: unresolved external symbol _D3DX10CreateEffectFromFileW@48 referenced in function "public: virtual void __...

ICU regex quoting

I am wondering if there is a way to quote a string in the ICU (c++) library. There exists "\Q" + string + "\E" but I am having generated input come in as the string provided. There does not seem to be any ICU quote regex method. Would just changing all "\E" in string to \\E work. ...

Install my compiled libs in the system to be used by an executable

Hi! I am using Xcode and, after some struggling, it is compiling my dynamic libraries okie dokie for now. My kinda-problem now is that I need to use those libs with another project, that is an executable. I would like that Xcode, after compiling my libs, copy them to the executable folder, or, better, copy the libs to a system dire...

handling large scale dataset

From the online discussion groups and blogs, I have seen a lot of interview questions are related to handling large scale dataset. I am wondering is there a systematic approach to analyze this type of questions? Or in more specific, is there any data structure or algorithms that can be used to deal with this? Any suggestions are really a...

Suggest user-mode filesystem filter framework plz

I need a user-mode filesystem filter (not virtual filesystem). One of such frameworks is http://eldos.com/cbflt/, but it has some bugs and I need an alternative. Suggest similar frameworks. ...

Function doesnt want to take my argument ?!

Hi.. A friend sent me his threading class. Now I just want to run a listener but the thread doesnt want to accept the function. I want to execute the function (defined in static class Networks) THREAD listen(void* args). THREAD is a #define THREAD unsigned __stdcall Networks::init() { listenerth = thread(); listenerth.run(listen, NU...