c++

CEvent-like behaviour with Boost.Thread

Problem in words: For my application, I have a class that reads from a serial port. It uses Windows primitives for COM port handling and had a thread for asynchronous reading. I'm trying to convert this away from Windows primitives using Boost libraries such as Boost.Asio and Boost.Thread. In the Windows port, my IO thread had severa...

C++ ctype facet for UTF-8 in mingw

In a project all internal strings are kept in utf-8 encoding. The project is ported to Linux and Windows. There is a need for a to_lower functionality now. On POSIX OS I could use std::ctype_byname("ru_RU.UTF-8"). But with g++ (Debian 4.3.4-1), ctype::tolower() don't recognize Russian UTF-8 characters (latin text is lowercased fine). O...

Multimap output after copying from map

This program stores pairs in a map, counting the number of times a word occurs. The goal is to have the data sorted by number of occurences and output in value/string form. Obviously the normal map sorts by the string key, so I had to reverse it. To do this I read in words, and increment their values appropriately in a map. Then I cre...

FRAPS alternative: Where to look and what for?

Howdy, later this year I'm going to have a lot of time on my hands, and I thought I'd start a "small" project for myself and release it as open source. I'd like to code my own Fraps alternative. (or continue with Taksi http://taksi.sourceforge.net ). Fraps is a video & sound recording programm, which captures the screen during gamepl...

Loading Nib and Displaying Window in Objective C++

I am trying to load a Nib from a C++ constructor with Objective C++. I have searched and found enough examples to get some code together but it doesn't display the window. Or any windows for that matter. Here is an example of the contructor: JokeSystem::JokeSystem() : fileSystem("/Library/Application Support/Jokes/") { try { ...

Simple C++ Error: "... undeclared (first use this function)"

Hey guys, I am working on my first C++ program for school. For some reason I am getting the following error when I try to compile it: `truncate' undeclared (first use this function) Full Source: #include <iostream> #include <math.h> using namespace std; #define CENTIMETERS_IN_INCH 2.54 #define POUNDS_IN_KILOGRAM 2.2 int main() { ...

Error: MFC projects cannot define _ATL_NO_EXCEPTIONS

I'm extending an open source project. After including afxcoll.h in a new C++ file in order to use CStringArray, I get this error: Error: MFC projects cannot define _ATL_NO_EXCEPTIONS I suspect I'll be able to fix the error by adding #defines or changing or rearranging the inclusion of headers, or, if that's not possible, using somethi...

Qt -- pass events to multiple objects?

I basically have 3 layers (Window > Scene > View) that each need to handle a mouseMove event without blocking the others. It seems only the youngest child is getting the event though. I was hoping I could process the event and then call event->ignore() to pass the event back up the stack, but it doesn't seem to be working. Some relevant...

How can I see the assembly code that is generated by a gcc (any flavor) compiler for a C/C++ program?

I am trying to optimize a lot of multiplications and pointer arithmetics and would like to see what the compiler does underneath when I put in optimization flags. --Edit-- How to restrict it to a specific function or a code block? --Edit_2-- How to let gcc generate a less verbose assembly-code? ...

Resizing a char[] at run time

I need to resize a char array[size] to char array[new_size] at runtime. How can I do this? ...

Memory leaks in C++ (via new+delete)

In order for an application to have no memory leaks, does the number of new in a C++ project match the number of delete? ...

VS C++ program only works when .exe is run from folder? [not VS debug]

Output from debug: File opened... File contents: Output from .exe (run via double click from /project/debug): File opened... File contents: line1 line2 etc. . . Source code: #include <iostream> #include <fstream> #include <regex> #include <string> #include <list> using namespace std; using nam...

Reading to end of file with istream_iterator and istream overload

I'm having some trouble reading data from a file into a vector of Orders. Code: #include <string> #include <vector> #include <fstream> #include <iostream> #include <iterator> using namespace std; class Purchase; class Order { public: string name; string address; vector<Purchase> items; }; class Purchase { public: s...

python object to native c++ pointer

Im toying around with the idea to use python as an embedded scripting language for a project im working on and have got most things working. However i cant seem to be able to convert a python extended object back into a native c++ pointer. So this is my class: class CGEGameModeBase { public: virtual void FunctionCall()=0; virtu...

C++ Vectors Problem

well i have most probably an extremly stupid problem but could not figure it out and I m about to lose my sanity hope someone can help vector<CvMat*> sample; for(int x = 0; x < 29; x += 2) { for(int b = 0; b < 22; b += 2) { cvmSet(g, 0, b, cvmGet(NormalVector, 0, x + b)); cvmSet(g, 0, b + 1, cvmGet(NormalVector, 0, ...

C++ creating and collecting structs in a loop

I want to create a struct from data harvested by line from a file. Each line necessitates a new struct, and the lines are accessed in a while loop. In C# I did this by creating anonymous structs and adding them to a list of structs. C++ would seem not to allow anonymous structs. I tried naming them with an incrementing variable, but this...

Get visible rectangle of QGraphicsView?

I've been pulling my hair out with this one for hours. There's a thread here about it, but nothing seems to be working. QGraphicsView::rect() will return the width and height, but the left and top values aren't set properly (always 0 -- ignoring the scrolled amount). I want it in scene coordinates, but it should be easy enough to transla...

C++ How to loop through a list of structs and access their properties

I know I can loop through a list of strings like this: list<string>::iterator Iterator; for(Iterator = AllData.begin(); Iterator != AllData.end(); Iterator++) { cout << "\t" + *Iterator + "\n"; } but how can I do something like this? list<CollectedData>::iterator Iterator; for(Iterator = AllData.begin(); Iterator != ...

Smiley face when assigning improper value type to struct property!!

I am somewhat wondering if I am losing my mind, but I swear to you, this code outputs smiley faces as the .name values!! what in the world is going on? Thus far it seems to only work when the value is 1, anything else properly gives errors. I realize the code is flawed -> I do not need help with this. #include <iostream> #include <fstr...

Why is the C++ syntax so complicated?

I'm a novice at programming although I've been teaching myself Python for about a year and I studied C# some time ago. This month I started C++ programming courses at my university and I just have to ask; "why is the C++ code so complicated?" Writing "Hello world." in Python is as simple as "print 'Hello world.'" but in C++ it's: # in...