c++

Deleting elements from STL set while iterating [NEW SOLUTION]

I need to go through a set and remove elements that meet a predefined criteria. This is the test code I wrote: #include <set> #include <algorithm> void printElement(int value) { std::cout << value << " "; } int main() { int initNum[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::set<int> numbers(initNum, initNum + 10); // ...

libiconv - iconv_open() default behavior?

According to the documentation of iconv_open() over: http://www.gnu.org/software/libiconv/documentation/libiconv/iconv_open.3.html "//TRANSLIT" means that when a character cannot be represented in the target character set, it can be approximated through one or several characters. and: "//IGNORE" means that characters that cannot be re...

How to query a CGI based webserver from an app written in MFC (MSVC 2008) and process the result?

Hi, I am exploring the option of querying a web-page, which has a CGI script running on its end, with a search string (say in the form of http://sw.mycompany.com/~tools/cgi-bin/script.cgi?param1=value1&amp;param2=value2&amp;param3=value3 ), and displaying the result on my app (after due processing of course). My app is written in MFC C++...

Fast read of certain bytes of multiple files in C/C++

I've been searching in the web about this question and although there are many similar questions about read/write in C/C++, I haven't found about this specific task. I want to be able to read from multiple files (256x256 files) only sizeof(double) bytes located in a certain position of each file. Right now my solution is, for each file:...

Simple map<> instantiation, I can't compile, please help

Why I can't compile this code? #include <map> using namespace std; class MyTest { template<typename T> void test() const; }; template<typename T> void MyTest::test() const { map<string, T*> m; map<string, T*>::const_iterator i = m.begin(); } My compiler says: In member function ‘void MyTest::test() const’: test.cpp:8: err...

Unoverloadable C++ operators

What operators can not be overloaded in C++? ...

Define own WM message for Message Pump in C++

How do I define my own WM (like WM_CLOSE, etc) message that can be handled by the message pump in C++? If that is even possible. ...

Using C++ classes in .NET

I have a set of classes that I've written in C++ for a code base that will run in Linux commandline. They primarily use the STL and no fancy features of the language. They've been tested, and work. I need to write a GUI app for the .NET framework that does things using logic I've written in those classes, but run on Windows. A critic...

How to check if aspect ratio auto adjustment is enabled in monitor

Game application is written in C++ and uses DirectX 8. I am getting a maximum monitor resolution to calculate it's aspect ratio. Then I use this value to fix game rendering (scale and set clipping to receive normal 4:3 image with black borders on wide screen monitors). How can I check if monitor is using aspect ratio auto adjustment no...

Can any function be a deleted-function?

The working draft explicitly calls out that defaulted-functions must be special member functions (eg copy-constructor, default-constructor, etc, (§8.4.2.1-1)). Which makes perfect sense. However, I don't see any such restriction on deleted-functions(§8.4.3). Is that right? Or in other words are these three examples valid c++0? struc...

huge C file debugging problem

Hello all. I have a source file in my project, which has more than 65,536 code lines (112,444 to be exact). I'm using an "sqlite amalgamation", which comes in a single huge source file. I'm using MSVC 2005. The problems arrives during debugging. Everything compiles and links ok. But then when I'm trying to step into a function with the ...

Variable arguments and function overloading

I am trying to improve SQLite error handling in an existing C++ program. I have a custom type SQLiteException, and I want to write a macro to print the line number, file name, and error messages from SQL. I have the following functions defined: LogMessage(LPCTSTR message); // Does the real work. Appends a timestamp to the message and...

Pointing class property to another class with vectors

I've got a simple class, and another class that has a property that points to the first class: #include <iostream> #include <vector> using namespace std; class first{ public: int var1; }; class second{ public: first* classvar; }; Then, i've got a void that's supposed to point "classvar" to the intended iteration of the clas...

Is long long in C++ known to be very nasty in terms of precision?

The Given Problem: Given a theater with n rows, m seats, and a list of seats that are reserved. Given these values, determine how many ways two friends can sit together in the same row. So, if the theater was a size of 2x3 and the very first seat in the first row was reserved, there would be 3 different seatings that these two guys can...

gluLookAt alternative doesn't work

Hey guys. I'm trying to calculate a lookat matrix myself, instead of using gluLookAt(). My problem is that my matrix doesn't work. using the same parameters on gluLookAt does work however. my way of creating a lookat matrix: Vector3 Eye, At, Up; //these should be parameters =) Vector3 zaxis = At - Eye; zaxis.Normalize(); Ve...

Nested If (x) checks - Better way to write this?

There are places where I check for valid pointers before I perform an operation with them; these checks can be nested pretty deeply sometimes. For example, I have if (a) { if (a->b()) { if (a->b()->c()) { a->b()->c()->DoSomething(); } } } I really don't like the look of this. Is there a way to turn this into ...

C++ - No match for 'operator=' when compiling using GCC

Hello! I recently tried building my own shared and weak pointers. Code that compiles using Visual Studio doesn't compile in GCC (4.5.0) with the following error: main.cpp: In function 'int main()': main.cpp:18:27: error: no match for 'operator=' in 'wp1 = weak_ptr<int>(((const shared_ptr<int>&)((const shared_ptr<int>*)(& sp1))))' weak_p...

C++: defining maximum/minimum limits for a class

Basically what the title says... I have created a class that models time slots in a variable-granularity daily schedule (where for example the first time slot is 30 minutes, but the second time slot can be 40 minutes); the first available slot starts at (a value comparable to) 1. What I want to do now is to define somehow the maximum an...

C++ OpenGL Window Kit

Besides Qt, GTK, wxWidgets... What are the recommendations for a cross platform, open source GUI framework library that works with OpenGL? ...

C++ - gcc-specific warnings

Hi! Got the following warning output when using GCC 4.5.0 & MinGW. Warning: .drectve `-aligncomm:___CTOR_LIST__,2 ' unrecognized Warning: .drectve `-aligncomm:___DTOR_LIST__,2' unrecognized What does it mean? I guess it's version-specific, because GCC 4.3.4 under cygwin didn't give that warning on the same project. If anyone had the ...