c++

How to install Boost on windows?

Hello, I added to c++ includes path to my folder with boost, but even example code from official site, dont work. Should I do smth else? I have got: boost/lambda/lambda.hpp: No such file or directory. EDIT: In Code Blocks I set "settings->compiler and debugger->search directories->compiler" to path to `/boost/. ...

Crazy C++ Vector iterator

I declare: typedef std::tr1::shared_ptr<ClassA> SharedPtr; And then: std::vector<SharedPtr> mList; And: typedef std::vector<SharedPtr>::iterator ListIterator; The return of mList.size() is 0, but when I use iterators, it iterates over the vector which is empty ! This is how I use the iterator: for(ListIterator it = mList.begin(...

Result of bitwise operator in C++

Testing a couple of compilers (Comeau, g++) confirms that the result of a bitwise operator of some "integer type" is an int: void foo( unsigned char ); void foo( unsigned short ); unsigned char a, b; foo (a | b); I would have expected the type of "a | b" to be an unsigned char, as both operands are unsigned char, but the compilers s...

C++ Windows Form Application Mysql Connection

I can't seem to figure out how to connect to mysql in my windows form application. I've installed all the proper libraries and have included them, thats not the issue. The issue is I can't find a tutorial on connecting to mysql. I've found some one console applications, tried them, but yet for some reason they do not work. I just need to...

how to convert an integer value to a specific ascii character in c++

I'm new to C++ and I'm trying to do something that should be pretty basic. I have a small loop in C++ that just displays a sequence of numbers and I would like to convert these numbers into specific ASCII characters. Something like this: for (int k = 0; k < 16; k++) { display(65+k); } And the result should look like t...

Memory allocation confusion

I created a class A and wrote the following function foo() class A { public: int a; }; A * foo() { A a1; return &a1; } int main() { A * a2; a2 = foo(); return 0; } The compiler gave me a warning as a1 is a local variable and I am returning its address from the stack (so its value can change unpredictably). Now I changed foo() to th...

How are malloc and free implemented?

Hello I want to implement my own dynamic memory management system in order to add new features that help to manage memory in C++. I use Windows (XP) and Linux (Ubuntu). What is needed to implement functions like 'malloc' and 'free'? I think that I have to use lowest level system calls. For Windows, I have found the funtions: GetProcess...

Dynamic instantiation in C++

I want my code to be extensible, in a way where at runtime I create the objects. For example, let's say I have a Grocery class which has an array of fruits and I want to fill this array of fruits with objects which derives from fruits. class Fruit{ }; class Grocery{ std::vector<Fruit> m_fruits; }; class Apple: Fruit{ }; class...

C++ Reference for Programmer Returning from Java

Hello everybody, Here's my situation: I taught myself C++ (albeit rather badly), and was later taught how to use Java in college. Returning to C++, I find myself confused by several things that differ from C++ to Java, for example memory management and avoiding memory leaks. What would be the best mode of returning to programming in C+...

cycle and erase elments from std::set

I have a std::set and I need to erase similar adjacet elements: DnaSet::const_iterator next = dna_list.begin(); DnaSet::const_iterator actual = next; ++next; while(next != dna_list.end()) // cycle over pairs, dna_list is the set { if (similar(*actual, *next)) { Dna dna_temp(*actual); // copy constructor dna_lis...

.NET C++ Windows Form Application Connecting To Mysql

nvm, I'll just keep trying or switch over to C# ...

Conditionals in Visual Studio 2010 Project files

In a Visual Studio 2010 C++ project file, is it possible to use conditionals to determine the presence of a library, and alter preprocessor flags, etc appropriately? To be more concrete, say we have a directory C:\libraries\MKL, i would like to #define MKL and add mkl_dll.lib as an additional dependency if that directory exists. Previo...

Two mutex condvar

If I have 2 mutexes locked, and I have a condvar for each one, is there an easy way to wait for either condvar to fire? I want to leave holding both locks again, and with (at least) one of the condvars having been signaled. ...

Segmentation fault while using priority queues

I have a priority queue with elements of a class named A I need elements from this queue which may be lower down the queue (lesses priority). So , I am trying to pop a few elements until i get the element of my choice. Once i get the element of my choice i am planning to push all the elements i stored temporary in an array. I have a loo...

Help with AA-Tree deletion

I am writing a non-recursive AA-Tree that is similar to std::multiset. I was wondering if anybody could notice any problems in my code to rebalance the tree for a deletion. The while loop in erase_rebalance() is going into an infinite loop when erase(iterator first, iterator last) is called. This is leading me to believe that the code to...

Practical pointer usage in c++

Most of my C++ programming experience has been projects for school. In that way, our usage of external libraries (ie boost) has been either prohibited or discouraged. Therefore we could not use smart pointers unless we wanted to write our own, which was usually beyond the scope of the projects. I'm just wondering in real world projects, ...

c++ extract string

hi. i have 26/01/10 09:20:20 MAL BIN BIN275 TSTCB U8L5 O/CR ..N UCOS Operated in string i want to extract column 36 into 60 that is BIN275 TSTCB U8L5 O/CR the last output i want to include O/CR is there any simple solution to settle this? already make this but not work. #include <iostream> #include <string.h> #include <fstr...

How to write a scrollable MFC custom control ?

I want to write my own chart control which requires scrolling. I found that there is a CScrollView but nothing like this for a control. Other toolkits like Cocoa, QT or GTK offer me a base class where i can set a content view which is displayed in a viewport and saves me from writting all of the scrolling code. ...

Setting all array elements to an integer

I have an array, int a[size]; I want to set all the array elements to 1 because some of the indexes in the array are already set to 1 so would it better checking each element using a conditional statement like, for (int index = 0; index < size; index++) { if (a[index] != 1) a[index] = 1; } or set all the indexes no matter...

Looking for an elegant and efficient C++ matrix library

Greetings, googling for that subject brings, e.g., MTL, exmat, LAPACK and also here. I also seem to remember that Microsoft Research released one, but can't put my hands on it. I look for advice from someone who actually used (or developed...) one of those, hoping to achieve a Matlab experience inside C++ (as much as possible). Thanks in...