c++

C++ functor to output iterator adapter

Given a functor appropriate for use with std::for_each and friends: template <typename T> struct Foo { void operator()(T const& t) { ... } }; std::for_each(v.begin(), v.end(), Foo<Bar>()); Is there some standard way to convert this into an output iterator appropriate for use with std::copy and friends? (or the opposite adaptatio...

Extension of Binary search algo to find the first and last index of the key value to be searched in an array.

The problem is to extend the binary search algorithm to find all occurrences of a target value in a sorted array in the most efficient way. Concretely speaking, the input of the algorithm are (1) a sorted array of integers, where some numbers may appear more than once, and (2) a target integer to be searched. The output of the algorithm...

VC++ how to change a picturebox from header file

HI, Just ran into a problem. How to I change a picturebox's picture from within a different header file. If I do it in the same .h file as the Form I am working on I use: sq1->Image = bi; (which loads in a bitmap) but when I do it from another header (i've included the correct header file), I get "sq1 is an undeclared identifier" and ...

What should the iterator type be in this C++ template?

While working on some graphics code a while back, I wrote Rect and Region classes using ints as the underlying coordinate holder, and that worked fine. The Region was implemented as a simple class extension to an STL list, and just contains a list of Rects. Now I also need the same kinds of classes using doubles as the underlying coordi...

C++ Serve PHP documents?

I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library? http://www.adp-gmbh.ch/win/misc/webserver.html I just downloaded that ...

Difference between these two statements? - C++

Hi, I'm a programming student trying to better understand pointers, one of the things I learned is that you can set a pointer to NULL. My question is, what's the difference between these two statements? When would each of them return true/false? if (some_ptr == NULL) if (*some_ptr == NULL) Thanks! ...

Odd duplicate symbols error

For a school project, the class was asked to write a String class to mimic the STL string class. I have all the code written, but the linker seems to be caught up on one of my operators. There are three files, String.h, String.cpp, and test2.cpp My Makefile looks like CC=gcc CXX=g++ CXXFLAGS+=-Wall -Wextra LDLIBS+=-lstdc++ all:test2...

Dealing with Floating Point exceptions

Hi, I am not sure how to deal with floating point exceptions in either C or C++. From wiki, there are following types of floating point exceptions: IEEE 754 specifies five arithmetic errors that are to be recorded in "sticky bits" (by default; note that trapping and other alternatives are optional and, if provided, non-default). * ...

Can I make a binary search tree with this?

I've made BSTs before. Can I use this to make a BST without modifications? template <class Item> class binary_tree_node { public: private: Item data_field; binary_tree_node *left_ptr; binary_tree_node *right_ptr; }; I tried making a BST with this but ran into some problems. For one thing, when I create the root node,...

Access Violation With Pointers? - C++

Hi, I've written a simple string tokenizing program using pointers for a recent school project. However, I'm having trouble with my StringTokenizer::Next() method, which, when called, is supposed to return a pointer to the first letter of the next word in the char array. I get no compile-time errors, but I get a runtime error which stat...

file selector in a qtablewidget

I'm trying to get one cell in a QTableWidget to be a box with button at end"..." with file selector, but don't know how to change what kind of widget the cell is. ...

Bidimensional Hashmaps in Java (and in general)

Hello, which is the best way to write a bidimensional hashmap efficiently in Java? Just to give an example of what I'm talking about: I'm developing some algorithms related to collective intelligence, these algorithms works by calculating correlation between pairs of elements.. Without caching these values, since they are calculated on...

Using getopt to parse program arguments in c++

I have a program which takes various command line arguments. For the sake of simplification, we will say it takes 3 flags: -a, -b, and -c and use the following code to parse my arguments int c; while((c = getopt(argc, argv, ":a:b:c")) != EOF) { switch (c) { case 'a': cout << ...

I can use SetWindowPos to place the window behind another window, but how do I place it in front of a given window?

SetWindowPosition second parameter is hWndInsertAfter which means behind. How do I place a window in front of another (above)? ...

URL browser origin in winpcap

is there anyway to know the origin(web browser) of a certain url/packet when programming with winpcap and c++? ...

How to I pass a table from lua into C++?

How would I pass a table of unknown length from lua into a bound C++ function? I want to be able to call the lua function like this: call_C_Func({1,1,2,3,5,8,13,21}) And copy the table contents into an array (preferably STL vector)? ...

How can I make this work with every delimiter? - C++

Hi, I just wrote a program that tokenizes a char array using pointers. The program only needed to work with a space as a delimiter character. I just turned it in and got full credit, but after turning it in I realized that this program only worked if the delimiter character was a space. My question is, how could I make this program wor...

How to know if the user is using multiple monitors

Hello, I'm trying to figure out a way to know if the user is using multiple monitors. I would like to know how to do this in native C++ (using the Win32 API) and with managed code (using the .NET Framework). Thanks in advance ...

Are structs necessary in binary search trees

I've looked at some code for BSTs and I can see that each node is a struct. Is this necessary? ...

Advantage of STL resize()

The resize() function makes vector contain the required number of elements. If we require less elements than vector already contain, the last ones will be deleted. If we ask vector to grow, it will enlarge its size and fill the newly created elements with zeroes. vector<int> v(20); for(int i = 0; i < 20; i++) { v[i] = i+1; ...