I have a sorted set (std::set to be precise) that contains elements with an assigned weight. I want to randomly choose N elements from this set, while the elements with higher weight should have a bigger probability of being chosen. Any element can be chosen multiple times.
I want to do this as efficiently as possible - I want to avoid ...
I inherited some C++ code and am trying to extend it and need to insert some objects into the following data structures in order to call a method, as the ObjectList is part of the parameter list that is passed to the method.
typedef std::vector <std::pair <std::string, ObjectPtr> > ObjectListBase;
typedef boost::shared_ptr <Object...
Hello
I know it was asked many times but I hadn't found answer to my specific question.
I want to convert only string that contains only decimal numbers:
For example 256 is OK but 256a is not.
Could it be done without checking the string?
Thanks
...
Not to be confused with how to split a string parsing wise, e.g.:
http://stackoverflow.com/questions/236129/how-to-split-a-string
I am a bit confused as to how to split a string onto multiple lines in c++.
This sounds like a simple question, but take the following example:
#include <iostream>
#include <string>
main() {
//Gives error...
I'm using OpenCV to iterate through an image and find the colour of each pixel, here's some of the code I'm using:
IplImage* img = cvLoadImage("c:\\test.png");
int pixels = img->height * img->width;
int channels = img->nChannels;
for (int i = 0; i < pixels*channels; i+= channels)
{
unsigned char red = img->imageData[i + 2];
u...
Hmm... Title is a bit of a mouthful, but I'm really not sure which part of this is causing issues, I've run through it a ton of times, and can't pinpoint why...
The idea is for a single Choice instance to be able to store any one value of any
of the types passed in to it's template list... It's kind of like a union, except
it keeps trac...
Hi,
How do I get the console handle of an external application?
I have a program running as a console. I have a 2nd program that will call GetConsoleScreenBufferInfo, but for that I need the console handle of the first program. Is it possible that given the HWND of the 1st program I can get its console handle?
...
I'm currently writing an app in C++ and found that some of its functionality would be better written in Haskell. I've seen instructions on calling Haskell from C code, but is it possible to do the same with C++?
EDIT: To clarify, what I'm looking for is a way to compile Haskell code into an external library that g++ can link with the ob...
I need to grab the path from the registry. The following code works except for the last part where I'm storing the path to the string. Running the debugger in Visual Studio 2008 the char array has the path, but every other character is a zero. This results in the string only being assigned the first letter. I've tried changing char res[1...
I have a problem regarding member pointers. The following code fails to compile using both Oracle Solaris Studio 12.2's CC and cygwin GCC 4.3.4 but works with Microsoft Visual C++ 2010:
struct A {
int x;
};
struct B : public A {
};
template<typename T> class Bar {
public:
template<typename M> void foo(M T::*p);
};
int main(int, c...
I have created a basic application with with windows api. It just displays a small window. I am starting from main function, getting the instance, created my windows class, etc. Everything works out fine. The problem I have however is that my custom icon will not display in the top left corner of the window or on the task bar, it just...
Under Linux, C++, and GCC, can I get a physical address for a given virtual address? I know I won't be able to manipulate the physical address as a physical address.
...
I'm trying to write a value to IO port 0x0466 in Windows.
Normally, it is 0x0000. To change it, I can physically short-circuit two headers on the board, and the value changes to 0x0001. And it will stay 0x0001 even when I open the circuit, until I restart/etc.
Now, the problem is, using software/IO port dll, I can write 0x0000 to port 0...
Given an compile-time constant integer (an object, not a macro), can I combine it with a string literal at compile time, possibly with the preprocessor?
For example, I can concatenate string literals just by placing them adjacent to each other:
bool do_stuff(std::string s);
//...
do_stuff("This error code is ridiculously long so I am g...
I am researching ideas for a PhD project.
One of my thoughts is writing a hypervisor (or bare metal) (?) so I could run multiple OS's without use of a true host operating system. Example I get a menu of some type of options to start operating systems, view what the 'console' of what is going on in an OS that is already running. Reboot O...
Hello ,
I developing a Antichat for counter strike using C++ .This AC need to take screenshots and upload them to a specified server.
The problem is that in Win7/Vista the Screenshots are black. I made researches on web but didn't find something that helped me.
I saw TAKSI sources, test all versions and Taksi 0.3 is good enough and not...
I'm trying to build a C++ extension for python using swig. I've followed the instructions below and the others to a T and can't seem to get my extension to load.
I ran across this article on the MinGW site under "How do I create Python extensions?"
http://www.mingw.org/wiki/FAQ
I also found these tutorials:
http://boodebr.org/main/p...
I notice in several API's, that you may create a struct which is used internally and has nothing. ex:
ALLEGRO_BITMAP *bmp;
...
bmp->(intellesense shows nothing)
how do these types of structures work? are they simply handled like this internally?
REAL_ALLEGRO_BITMAP *realbmp = (REAL_ALLEGRO_BITMAP*)bmp;
or is there a cleaner soluti...
I am using this code to sink events in a IWebBrowser2 webbrowser on c++:
STDMETHODIMP AdviseSink::Invoke(DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS* pDispParams,
...
class Catalog
{
// string StationTitle;
string StationLocation;
public:
string StationTitle;
Catalog()
{
StationTitle = "";
StationLocation = "";
}
Catalog(string Title, string Location)
{
StationTitle = Title;
StationLocation = Location
}
void SetTitle(string Title) { StationTitle = Tit...