c++

C# iterators and pointers?

I know there are no pointers in C#, but I am trying to figure out how to do the following, which I would have done with pointers (or better yet, iterators) in C++ (I am taking a course in C#, but I already know C++). We got an assignment to write a simple "store" program (inventory, transactions, etc.). My first idea (coming from C++) w...

How to enumerate a BOOST_ENUM with BOOST_FOREACH ?

Hi, Can somebody please explain me how to enumerate a BOOST_ENUM using BOOST_FOREACH ? The example below show that I got it to work with std::for_each, but not with BOOST_FOREACH. Sample code : BOOST_ENUM_VALUES( MyEnum, const char *, (xMin)("xMin") (xMax)("xMax") (yMin)("yMin") (yMax)("yMax") ); void bla...

Basic Code::Blocks problem.

I apologize for asking a question of this caliber. I am at my wits end and have spent to much time trying to figure out how to get the side bar I closed back. I closed the "management" (the box with all the headers and .cpp's) and "messages" (where the compiler errors are displayed) box after I created a project. Now I can't get them bac...

passing a 2 dimensional vector to a function

Hi Guys, How to pass a 2 dimensional Vector to a function in CPP ? I saw the examples for 1 dimension but not for 2 dimensions. If it is passed, is it passed by value or by reference ? vector< vector<int> > matrix1(3, vector<int>(3,0)); //Matrix Declaration. printMatrix(&matrix1); // Function call void printMatrix(vector< vector<int...

Calling primitive operator-functions explicitly in C++

int a, b, c; //do stuff. For e.g., cin >> b >> c; c = a + b; //works c = operator+(a,b); //fails to compile, 'operator+' not defined. This on the other hand works - class Foo { int x; public: Foo(int x):x(x) {} Foo friend operator+(const Foo& f, const Foo& g) { return Foo(f.x + g.x); } }; Foo l(5), m(1...

calling a function from a friend function defined in a header in c++

Hi all, I have redefined the >> operator as a friend function in a template class in the header. In it, i need to call another function called inputHelper that I have also defined in the header. (input helper is recursive) the header file is as follows: template< typename NODETYPE > class Forest { /* (other friends) */ friend ...

Where to find C++ reference for Internet Explorer extension

I've just started building an extension for internet explorer using c++. I haven't been able to find the reference for it, where is it? ...

How to specify color using a VARIANT

I need to set the color of an HTML element, I've managed to get a reference to the style but I now need to pass a VARIANT to the put_color method and I can't find information regarding how you construct a variant. How would I go about specifying the color #ffaaaa for the put_color call? CComPtr<IHTMLStyle> spStyle = htmlElement->get_st...

How do tabs work for text boxes?

I'm making a game gui api and I'm wondering how to implement tabs. I'm using freetype for text. When I try to render '\t' It looks like a square. I'm wondering how tabs are implemented because they are not a fixed width. Thanks ...

Converting from XML to a C++ Object

I'm working on a C++ project, and wanted to get some inputs from developers with similar experience. The task is to connect to a web service which gives the results in an XML form. My role in the task is once I receive the XML form, I need to convert the XML into a C++ object and parse the XML data to the C++ object. Following are my ...

How to get the actual COM port number with SetupDiGetDeviceRegistryProperty

I'm trying to get a list of available COM ports with the "Windows 2000"-method explained here: http://www.codeproject.com/KB/system/setupdi.aspx My current code: http://pastebin.ca/1977670 This is what I get: \\?\ftdibus#vid_0403+pid_6001+ftf479xra#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73} USB Serial Port (COM13) USB Serial Port \\?...

Deleting pointers in a vector

Hi, I have a vector that I fill with pointers to objects. I am trying to learn good memory management. I have a few general questions: Is it true that when I am done with the vector I must loop through it and call delete on each pointer? Why don't I have to call delete on the vector (or any other variable I declare without the new stat...

C++ object created with new, destroyed with free(); How bad is this?

Hello, all. I am working on modifying a relatively large C++ program, where unfortunately it is not always clear whether someone before me used C or C++ syntax (this is in the electrical engineering department at a university, and we EEs are always tempted to use C for everything, and unfortunately in this case, people can actually get ...

VS2008 Compile error with <winsock2.h>

Getting heaps (105) of redefine & syntax errors when trying to compile my VS2008 c++ project with <winsock2.h> included. Running Windows 7 64bit. I have googled and searched and the answer seems pretty uniform but it doesn't seem to work for me. Tried putting #include <winsock2.h> before #include <windows.h>. Also tried not including <w...

utf-8 encoding a std::string?

I use a drawing api which takes in a const char* to a utf-8 encoded string. Doing myStdString.cstr() does not work, the api fails to draw the string. for example: sd::stringsomeText = "■□▢▣▤▥▦▧▨▩▪▫▬▭▮▯▰▱"; will render ??????????????? So how do I get the std::string to act properly? Thanks ...

C assignment of int

Hi, When you see code like this in C, what's the order of assignment? int i = 0, var1, var2; I don't understand the syntax... ...

Compilation error in usage of templates

Hi, I have below code. template <class T> class Test { public: template<class T> void f(); //If i define function here itself, error is not reported. }; template <class T> void Test<T>::f() { } //Error here. int main() { Test<float> ob; ob.f<int>(); } It produces below error. error C2244: 'Test<T>::f' : unable t...

Stringstream write() problem while "overwriting"

Currently, I have a stringstream called Data. I am seeking to the beginning of the stringstream by using: Data.seekp(0, std::ios::beg); Then, I try writing 2 integers to the first 8 bytes of the stringstream (previously, the first 8 bytes were set to 0) Data.write(reinterpret_cast<char*>(&dataLength),sizeof(int)); Data.write(reinterp...

size of std::vector with struct elements

Hi everybody, I'm having trouble getting the right size of a vector with struct elements. The element class is defined like this (I didn't omit any detail even though I think the only relevant fact is that it is a class containing an int and two doubles): class Interval { public: Interval(int _i = 0, scalar _l = 0, scalar _r = 0) :...

Deleting a character from a string

Hi, I wanted to write a code that would delete a given character from a string. I have come up with the following snippet. Now, while this does my work, it is giving me a worst case complexity of O(n^2). Can anyone help me on improving this. #include<iostream.h> #include<conio.h> #include<stdio.h> void Push(char *, int i); int n=6;...