c++

Capturing the input stream as a user types

I am working on a C++ based command line tool and I want to capture the user's keystrokes in real-time without requiring them to hit Return to commit the input. I can't seem to find an iostream call to support this kind of behavior but I recall from my college years that it can be done. Can anyone point me in the right direction? ...

Best way to insert items from a Derived class's constructor into a Base class's private std::vector?

I have these classes: class Base { ... private: std::vector<X> v; }; class Derived : public Base { Derived(X*, int n); }; where the constructor of Derived is passed an array of item Xs, which I need to insert into my vector v in the Base class. (X is a smart pointer) Currently I see two ways to do this: Create a function in Base: ...

push_back of STL list got bad performance?

I wrote a simple program to test STL list performance against a simple C list-like data structure. It shows bad performance at "push_back()" line. Any comments on it? $ ./test2 Build the type list : time consumed -> 0.311465 Iterate over all items: time consumed -> 0.00898 Build the simple C List: time consumed -> 0.020275 Iterate o...

How do I repass a function pointer in C++

Firstly, I am very new to function pointers and their horrible syntax so play nice. I am writing a method to filter all pixels in my bitmap based on a function that I pass in. I have written the method to dereference it and call it in the pixel buffer but I also need a wrapper method in my bitmap class that takes the function pointer an...

How to change this C++ code to make input work better

cout << "Input street number: "; cin >> streetnum; cout << "Input street name: "; cin >> streetname; cout << "Input resource name: "; cin >> rName; cout << "Input architectural style: "; cin >> aStyle; cout << "Input year built: "; cin >> year; The problem ...

Why do Java/C# edge out C++ as the recommended language to learn OOP on SO?

I noticed after reading the answers/discussion to this question (What is the best language to learn OOP on?) - that more and more people are recommending C# or Java over C++ to learn OOP on. A simple term search on that answer page results in 10 hits for C++, 21 for C# and 27 for Java. Now, I understand that these 2 languages fix a lot ...

Templates, and C++ operator for logic: B contained by set A

In C++, I'm looking to implement an operator for selecting items in a list (of type B) based upon B being contained entirely within A. In the book "the logical design of digital computers" by Montgomery Phister jr (published 1958), p54, it says: F11 = A + ~B has two interesting and useful associations, neither of them having much to do...

Coupling between controller and view

The litmus test for me for a good MVC implementation is how easy it is to swap out the view. I've always done this really badly due to being lazy but now I want to do it right. This is in C++ but it should apply equally to non-desktop applications, if I am to believe the hype. Here is one example: the application controller has to check...

Sub-classing templated class without implementing pure virtual method

I have the following class definition: template<typename QueueItemT> class QueueBC { protected: QueueBC() {} virtual ~QueueBC() {} private: virtual IItemBuf* constructItem(const QueueItemT& item) = 0; } I created the following sub-class: class MyQueue : public QueueBC<MyItemT> { public: MyQueue() {} virtual...

Active C++ project to contribute to

I am a self-taught c++/java programmer (I will be starting uni in August though!). I have worked on one project in which I was part of an active team. I really felt I learnt the most and gained a lot of experience while working with the team. Unfortunately it was a small closed source project which has recently taken a slumber. I'm l...

lock file so that it cannot be deleted

I'm working with two independent c/c++ applications on Windows where one of them constantly updates an image on disk (from a webcam) and the other reads that image for processing. This works fine and dandy 99.99% of the time, but every once in a while the reader app is in the middle of reading the image when the writer deletes it to refr...

What is a Cursor Linked List? [C++]

My professor provided me with a file called CursorList.cpp that implements a "Cursor Linked List". The problem is - I have no idea what that even is! Could anybody give me the gist of it? Thanks! ...

Multicolor text in TreeView (Embarcadero RAD studio)

Hello everyone, I am writing a piece of software in C++ RAD studio 2010 and got a question about TreeView. Is it possible to use multicolor text in a TTreeView component? I could not find a easy way but to implement custom drawing which seems to be weird nowadays. Are there any straight-forward ways or maybe additional components tha...

boost::program_options bug or feature?

Very simple example: #include <string> #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int argc, char* argv[]) { po::options_description recipients("Recipient(s)"); recipients.add_options() ("csv", po::value<std::string>(), "" ) ("csv_name", po::value<unsi...

What is the best way to store incremental downloaded data?

Inspired by Chromium's sha1 class, I am thinking to store incrementally downloaded data using std::string // pseudo-code char buff[BUFF_SIZE]; std::string data; do { size = ReadInternetFileTo(buff,BUFF_SIZE); data.append(buff,size); } while (not_finished); Any foreseeable problems with this method or better way to do it? ...

C++ template meta-programming, number of member variables?

hello Is it possible in C++ to determine number of variables/fields in the generic class? for example // suppose I need metaclass number_members determines number of members struct example { int i, j; }; assert(number_members<example>::value==2); I looked through mpl but could not find implementation. thanks. ...

Accessing XUL anonymous content using C++

Hi All, I am writing Firefox extension using C++. I am trying to access XUL:tabox element in "TabOpen" event handler, but I am unable access any XUL element. I am putting here pseudocode of my extension for reference: HandleEvent() { if (event type is TabOpen) { nsCOMPtr<nsIDOMNode> OriginalNode = do_QueryInterface(event...

Which is faster in memory, ints or chars? And file-mapping or chunk reading?

Okay, so I've written a (rather unoptimized) program before to encode images to JPEGs, however, now I am working with MPEG-2 transport streams and the H.264 encoded video within them. Before I dive into programming all of this, I am curious what the fastest way to deal with the actual file is. Currently I am file-mapping the .mts file ...

What are the advantages and disadvantages of using boost::iterator_facade?

Yep -- the title pretty much sums it up. I've got quite a few types that implement iterator concepts, and I'm wondering if it's worthwhile to pull in this boost header instead of implementing things manually. So far: Advantages Well specified Less likely to have bugs ...

Learning Visual C++ 2008 and C++ at the same time? Any resources to recommend?

Hey guys, I am trying to learn Visual C++ 2008 and C++ at the same time to get involved with sourcemod, a server side modding tool for valve games. However I have never touched Visual C++ or C++ in general, and doing some preliminary research I am quite confused on these different versions of C++ (mfc, cli, win32), and why a lot of peop...