c++

Converting UTF-8 to WIN1252 using C++Bulder 5

I have to import some UTF-8 encoded text-file into my C++Builder 5 program. Are there any components or code samples to accomplish that? ...

Can I use CreateFile, but force the handle into a std::ofstream?

Is there any way to take advantage of the file creation flags in the Win32 API such as FILE_FLAG_DELETE_ON_CLOSE or FILE_FLAG_WRITE_THROUGH as described here http://msdn.microsoft.com/en-us/library/aa363858(VS.85).aspx , but then force that handle into a std::ofstream? The interface to ofstream is obviously platform independent; I'd lik...

Will this lead to a memory leak in C++?

Hello, I have a C++ memory management doubt, that's (obviously) related to references and pointers. Suppose I have a class Class with a method my_method: OtherClass& Class::my_method( ... ) { OtherClass* other_object = new OtherClass( ... ); return *other_object; } Meanwhile in a nearby piece of code: { Class m( ... ); ...

How to load digital signals from a USB port into memory?

My friend is working on a project in which he needs to get some digital signals into a computer to display/manipulate them. So I advised him to insert those signals into a USB port due to it's popularity (because the device (which outputs the signals) and the program used for display and manipulation should both be designed for real wor...

Is there a way to call an unmanaged (not COM) dll from C# application?

Hello, Is there a way to use (reference) a DLL written in an unmanaged C++ (not a COM library) in my C# application? When I try to reference it from within Visual Studio, I get 'not a COM object' error message. Maybe there is some kind of translator\router that would COMify my DLL reference? I have no clue how COM and COM interop work...

What is the precision of long double in C++?

Does anyone know how to find out the precision of long double on a specific platform? I appear to be losing precision after 17 decimal digits, which is the same as when I just use double. I would expect to get more, since double is represented with 8 bytes on my platform, while long double is 12 bytes. Before you ask, this is for Pro...

Python as your main language. Possible?

I am currently attending college and the languages that I will 'know' by graduation are C++ and Java. That being said, i am also in the process of teaching myself Python. I know that every programming language has its own pros and cons, but would it be possible to become a python developer out of school? I always have more 'fun' programm...

How to properly overload the << operator for an ostream?

I am writing a small matrix library in C++ for matrix operations. However my compiler complaints, where before it did not. This code was left on a shelf for 6 months and in between I upgraded my computer from debian etch to lenny (g++ (Debian 4.3.2-1.1) 4.3.2 ) however I have the same problem on a Ubuntu system with the same g++. Here i...

C++ Why is this vector access giving a Runtime Error?

Hi, I've singled out a runtime error on this line of my code: for (synsAuxCopyIndex=1; synsAuxCopyIndex<synsAux.size(); synsAuxCopyIndex++) Which is runnhing inside the pushSynonyms(string synline, vector<WordInfo> &wordInfoVector) function. I don't get why is this particular line generating the error, as I don't think I'm indexing an...

Programming style of method declaration of get/set method variables in C++?

Should you declare the getters/setters of the class inside the .h file and then define them in .cpp Or do both in .h file. Which style do you prefer and why? I personally like the latter wherein all of them are in .h and only methods which have logic associated with it other than setters/getters in .cpp. ...

How to use std::foreach with parameters/modification

I've found myself writing for(int i=0;i<myvec.size();i++) myvec[i]->DoWhatever(param); a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things like for(int i=0;i<myvec.size();i++) if(myvec[i]->IsOK()) myvec[i]->DoWhatever(p...

Mixed Language Programming, VB and C++, noob problems with API and pointers

My problem is with understanding the finer point of mixed langage programming and accessing API's in external libraries. My skills at C++ are nonexistent and at VB, mediocre. I have a c++ dll compiled (portaudio library), and am trying to access it from VB (Visual Studio 2005). I am getting MarshallDirectiveException errors when call...

Comparing two integers without any comparison

Is it possible to find the greatest of two integers without any comparison? I found some solutions: if(!(a/b)) // if a is less than b then division result will be zero. { cout << " b is greater than a"; } else if (!(a-b)) // we know a is greater than or equal to b now. check whether they are equal. { cout << "a and b are equa...

CreateTimerQueueTimer callback and race condition

I'm using timer queues in my application, and pass a pointer to one of my own C++ Timer objects as the 'parameter' to the callback (in CreateTimerQueueTimer). I then call a virtual method on the object in the callback. The destructor of the Timer object will make sure to cancel the timer using DeleteTimerQueueTimer(). static void callb...

Using MSHTML for the GUI in C++, is there perhaps a tutorial?

I would like to migrate my app to using MHTML for the GUI since it would be much easier to experiment with layouts without rewriting the C++ every time. Is there a tutorial? What I found is unfortunately not what I need, which is: Feed it HTML from memory Receive events such as onclick, etc., back in my C++ code Manipulate it through ...

Is std::ifstream significantly slower than FILE?

I've been informed that my library is slower than it should be, on the order of 30+ times too slow parsing a particular file (text file, size 326 kb). The user suggested that it may be that I'm using std::ifstream (presumably instead of FILE). I'd rather not blindly rewrite, so I thought I'd check here first, since my guess would be the...

How to use the "removed" elements after std::remove_if

Say we've got: struct IsEven { bool operator() (int i) { return i % 2 == 0; } }; Then: vector<int> V; // fill with ints vector<int>::iterator new_end = remove_if(V.begin(), V.end(), IsEven()); V.erase(new_end, V.end()); works fine (it leaves V with only the odd integers). But it seems that the elements from new_end to V.end() ar...

No Dumpbin.exe

I do not see dumbin.exe on my sysytem . I have Visual Studio 2005 on my system . When I type dumpbin on command line , it says unrecognizable command . Does not it come ( by default ) with Visual Studio , or do I have to explicitly add this tool . ...

ifstream, end of line and move to next line?

how do i detect and move to the next line using std::ifstream? void readData(ifstream& in) { string sz; getline(in, sz); cout << sz <<endl; int v; for(int i=0; in.good(); i++) { in >> v; if (in.good()) cout << v << " "; } in.seekg(0, ios::beg); sz.clear(); getline(in, sz); cout...

c++ ifstream, detect if letter or EOLine?

I have this function to read in all ints from the file. The problem is when i read letters i trigger a new line and i always seek by 1 and not to the end of line. How can i write this function better? int v; while (!in.eof()) { while (in >> v) cout << v << " "; cout << endl; if (in.eof()) break; ...