c++

How to rollback lines from cout ?

Hi, I'm coding a task monitoring, which updates tasks' progress using cout. I'd like to display one task progress per line, therefore I have to rollback several lines of the console. I insist on "several" because '\b' does the job for one line, but does not erase '\n' between lines. I tried std::cout.seekp(std::cout.tellp() - str.leng...

include objective-c header in c++ file

Is there a way to include an objective-c header from a cpp? Because when I try to #include "cocos2d.h" from a cpp .h file, a lot of errors complaining about @'s and -'s are showing up. Can c++ files include obj-c headers like that? ...

Using pair as key in a map (C++ / STL)

Hello, I want to use a pair from STL as a key of a map. #include <iostream> #include <map> using namespace std; int main() { typedef pair<char*, int> Key; typedef map< Key , char*> Mapa; Key p1 ("Apple", 45); Key p2 ("Berry", 20); Mapa mapa; mapa.insert(p1, "Manzana"); mapa.insert(p2, "Arandano"); return 0; } But the compiler...

Problems importing a .lib into another project.

I'm using Visual Studio 2008 under Windows 7. I have a .lib and accompanying .h files (which make use of wxWidgets if that makes a difference) which compile without any issues. I'm trying to import that library into a GUI project but when I do, the main class I'm interested in doesn't appear to be there? I've added #include "MyLib.h" ...

Is Python-based software considered less-professional than C++/compiled software?

I'm working on a plugin for some software that I'm planning on selling someday. The software I'm making it for has both a C++ SDK and a Python SDK. The C++ SDK documentation appears incomplete in certain areas and isn't documented that well. The Python SDK docs appear more complete and in general are much easier to work with. So I'm t...

Reasons to choose C over C++

Possible Duplicate: Whats the advantage of using C over C++ or is there one? Hello all. I was wondering why so many people continue to code in C when C++ has now been out for such a long time. What advantages/disadvantages are there?? I heard that there are differences (ie. advantages to C) in the way that linking is done, b...

C++ WinAPI: handling long file paths/names

I'm looking at handling longer file paths in my windows application. Currently, I have a text box (edit box) in which a user can type an absolute file path. I then read that typed file path, using GetWindowText, into a string declared like so: TCHAR FilePath[MAX_PATH]; Obviously, here i'm relying on the MAX_PATH constant which limits m...

C++ noob question: pointers and overloaded []

I've been staring at this for a while and not getting very far. FruitBasketFactory, FruitBasket, and Fruit are three classes from an API I'm using. My goal is to make a fruit basket and then retrieve the fruit. According to the FruitBasketFactory.hpp: const FruitBasket* getFruitBasket() const; and then in the FruitBasket.hpp siz...

C++ Template class inheriting another template class with a template-specified input type

Possible Duplicates: GCC problem : using a member of a base class that depends on a template argument Why does GCC need extra declarations in templates when VS does not? Why doesnt a derived template class have access to a base template class iphone compiler inherited templated base classes with passed through type not being e...

Appropriate use of friend? Container class designed to manipulate objects of specific type

Lets say you have a FooManager made to manage multiple objects of type Foo. The FooManager needs to see some parts of its Foos to evaluate their current state. Before I was using a few accessors in Foo to see these parts, until I realized that FooManager is the only class actually using these. I decided to make FooManager a friend of Foo...

How to get rid of padding bytes between data members of a struct

Hi colleagues I have a binary file with "messages" and I am trying to fit the bytes inside the right variable using structs. In my example I used two types of messages: Tmessage and Amessage. #include <iostream> #include <fstream> #include <stdlib.h> #include <string> #include <iomanip> using namespace std; struct Tmessage { un...

Extreme memory usage for individual dynamic allocation

Hi folks, here's a simple test I did on MSVC++ 2010 under windows 7: // A struct with sizeof(s) == 4, e.g 4 bytes struct s { int x; }; // Allocate 1 million structs s* test1 = new s[1000000]; // Memory usage show that the increase in memory is roughly 4 bytes * 1000000 - As expected // NOW! If I run this: for (int i = 0; i < 10000...

Templates, STL, C++

I wrote this routine to order items, keep only unique items, where it takes in an array of type T, and the size of the array. It returns the new size of the array after processing. template <class T> int reduce(T array[], int size) { T *begin = array; T *end = array + size; sort(begin, end); T *end_new = unique(begin,...

How can I safely (and easily) count *all* instances of a class within my program?

I would like to be able to instantiate a particular (and otherwise normal) class (the source of which I can modify) and count the number of times the class has been instantiated (e.g. like this). But I would like to include all instances in my total count, even some which are created via the copy constructor in standard containers. Woul...

What are the problems with this producer/consumer implementation?

So I'm looking at using a simple producer/consumer queue in C++. I'll end up using boost for threading but this example is just using pthreads. I'll also end up using a far more OO approach, but I think that would obscure the details I'm interested in at the moment. Anyway the particular issues I'm worried about are Since this code is...

Template syntax help

Two questions for an assignment, first is the first set of errors for my template in a the CharComparator.h file, I don't see why it is complaining. The second question is why that I added include "CharComparator.h" to my main.cpp file, I get a bunch more of compiler errors. Here are my files: CharComparator.h #ifndef CHARCOMPARATOR_...

How to marshall c++ char* to C# string using P/INVOKE

Hey guys, I'm new to C++. I'm calling a C++ function from C# using a PINVOKE and wanting to get a string back as an out parameter. However I just get an empty string back. The int out parameter works fine. Importing: [DllImport ( @"UnamanagedAssembly.dll", CharSet = CharSet.Ansi)] public static extern int Activate(ref int numActivat...

Hook a QT Application with C++ to capture textname of the application

Hi guys, I have a simple QT application running on Win32 platform. I need to write a C++ program described as: the input is the windows handle of that QT application, which is already available, the output is the text name ( AKA caption ) of the application. I hope someone will show me the way to do this right. Thanks a lot. Smile ...

C++ type casting

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? Until a few days ago, I've always used C style type casting in C++ because it seemed to work good. I recently found out that using C in C++ is very bad.. I've never really used C++ casting before, so I'm wondering if someone could tell me ...

Do I need to define `operator==` to use my class with standard containers?

I'd like clarification on the C++ standard, specifically where it says (my interpretation) in section 20.1.3 that "for class T and an instance of class T called x, T(x) must be equivalent to x" for the class to work with standard containers. I couldn't find a definition of 'equivalent'. Does this mean that I have to define operator== a...