c++

Boost.Program_options syntax

I'm currently reading the Boost.Program_options tutorial. Here is some of the code they introduce: // Declare the supported options. po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>(), "set compression level") ; I understand the purpose behind ...

Using comparator for STL set

Check the following code: string toLowerCase(const string& str) { string res(str); int i; for (i = 0; i < (int) res.size(); i++) res[i] = (char) tolower(res[i]); return res; } class LeagueComparator { public: bool operator()(const string& s1, const string& s2) { return toLowerCase(s1) < toLower...

Calculating with C/C++ using float.

Hi. I'm practising with C, writing simple programs. The little program below should just get 3 numbers from the user and multiplicate them. My problem is that i'm a bit confused about the variable type i must use. I want the program to take any number such as 5, 5.673434, 99.123 and so, calculate with them and print out a rounded flo...

How do I install FLTK for VS2010?

Hey guys, this is my first post on here so please bare with me. I'm doing a project for school have to incorporate a form of GUI. Sadly, I have no experience with GUIs whatsoever so I just spend the last few hours comparing the various toolkits and settled on FLTK for it's lightweightness. I also spent the time attempting to install FLT...

how to deallocate memory in C++

I have a class A where I construct an object of class B named bb. After constructing the object bb, I run in to a exception in Class A code which is caught by an exception handler. Now my question is how to deallocate the memory of object B in the exception handler? ...

Create automation macro support within an application

Hi All, I need to get an automation macro like thing within our desktop application. The desktop app will probably be in VB.NET or C#.net. The reason is to enable the user to record and replay certain tasks that they'd like to automate. Something like macros within office apps and visual studio. The first thing that comes to my mind is ...

Problem compiling C++ program

Hi, there! I'm writting graph classes. I've wrote such code in "Graphs.h" : #include <vector> #include <iostream> using namespace std; struct Edge{ int v,w; Edge(int v=-1, int w=-1):v(v),w(w){} }; class Graph { protected: int Ecnt, Vcnt; bool digraph; public: Graph(int V, bool isDirected) :Ecnt(0),Vcnt(V),digraph(isDirected) {} ~...

Instantiation of objects in conditionals c++

Hi all, let's say I want to instantiate a different type of object depending on certain circumstances, so i would instantiate them inside the body of an if statement. The problem is if you want to use that object later, you need to declare it before instantiation. How does one declare a generic object. Is there something similar to th...

Particle library

Hello, maybe someone knows a good crossplatform particle library? I know Pyro particle library, but it's not crossplaftorm and free. There is also Magic Particles (Probably, the best version I need) but there is only theoretical possibility to make a port on Linux. ...

Initializing a member array in constructor initializer

class C { public: C() : arr({1,2,3}) //doesn't compile {} /* C() : arr{1,2,3} //doesn't compile either {} */ private: int arr[3]; };*/ I believe the reason is that arrays can be initialized only with = syntax, that is: int arr[3] = {1,3,4}; Questions How can I do what I want to do (that is, initialize an array in a ...

Disabling stdout buffering of a forked process

Hi, I wrote a code in C/C++ which forks a child process, duplicates the stdin/stdout into a pipe ends and calls execvp. Everything is working fine (i.e. the output from stdin/err/out is captured by the parent process) The problem is that the child stdout is buffered. so if the child code looks like this: printf("Enter any key and hi...

How to convert plain text to ODF?

Hi everybody! I am searching for C/C++ library for txt -> odf conversion. I've already checked http://odftoolkit.org but it has only Java version. Main criterion is a ease of use. ...

What C/C++ library to use for HTML DOM building/changing?

I am using perl module HTML::DOM (link to CPAN) for building HTML DOM tree from HTML code and then changing it using standard DOM's removeAttribute, removeChild, innerHTML, createElement and so on. But, I have found out it's really, really slow and eating too much memory (it's fully in perl, anyway). So, I thought that there will be som...

lex_cast: Make formatted streams, unformatted

I once saw this nice little snippet of code below, here at SO: template<typename to_t, typename from_t> to_t lex_cast(const from_t &arg) { to_t ret; std::stringstream os; os << arg; os >> ret; return ret; } This mimics boost::lexical_cast. Usage: string tmp = ::lex_cast<string>(3.14); However, due to the default...

How do I check against all vector elements?

This compiles and runs ok on Visual C++ 2010 Express but it only checks against the [2] element: "Fish". int main() { vector<string> words; string temp; vector<string> disliked(3); disliked[0] = "Broccoli"; disliked[1] = "Mushrooms"; disliked[2] = "Fish"; while (cin >> temp) ...

list of debuggers available for c++

Hi Can anyone tell me what are the debugger(s) available for c++ language. Also please provide details about those debugger or reference to get details for the same. Thanks, -Pravin ...

I think I may have come up with an example of rvalue of array type

C++03 §4.2 N°1: An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer to T.” The result is a pointer to the first element of the array. What has been confusing in this statement for a long time for me was that I didn't quite understand what an rvalue of array type woul...

SDL changing cursor to Windows default

I'm making a simple windowed game and I want a standard system cursor instead of SDL's black one. Is this possible without manual creation of cursor? ...

Can I determine how much valid memory is addressed by a char * argument?

I have a function like: // string is a null-terminated char array. Replace all a in the string with b void ReplaceCharInString(char *string, char a, char b) { // loop over the string char by char, to find all "a"s and replace them with "b" } I'm doing the defensive programming. The problem is the implementation replies on the client t...

What is 0xFF and why is it shifted 24 times?

#define SwapByte4(ldata) \ (((ldata & 0x000000FF) << 24) | \ ((ldata & 0x0000FF00) << 8) | \ ((ldata & 0x00FF0000) >> 8) | \ ((ldata & 0xFF000000) >> 24)) What does that 0x000000FF represent? I know that decimal 15 is represented in hex as F, but why is it << 24? ...