c++

How can i tell if a given path is a directory or a file? (C/C++)

I'm using C and sometimes i have to handle paths like C:\Whatever, C:\Whatever\ or C:\Whatever\Somefile Is there a way to check if a given path is a directory or a given path is a file? :O ...

Help improve this INI parsing code

This is something simple I came up with for this question. I'm not entirely happy with it and I saw it as a chance to help improve my use of STL and streams based programming. std::wifstream file(L"\\Windows\\myini.ini"); if (file) { bool section=false; while (!file.eof()) { std::wstring line; std::getline(file, line); ...

What #defines are setup by xCode when compiling for iPhone

I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like #ifdef IPHONE_SDK.... Presumably xCode defines something, but I can't see anything under project properties, and google isn't much help. ...

Style question: Writing "this." before instance variable and methods: good or bad idea?

One of my nasty (?) programming habits in C++ and Java is to always precede calls or accesses to members with a this. For example: this.process(this.event). A few of my students commented on this, and I'm wondering if I am teaching bad habits. My rationale is: 1) Makes code more readable — Easier to distinguish fields from local variab...

Why doesn't C++ have a garbage collector?

I'm not asking this question because of the merits of garbage collection first of all. My main reason for asking this is that I do know that Bjarne Stroustrup has said that C++ will have a garbage collector at some point in time. With that said, why hasn't it been added? There are already some garbage collectors for C++. Is this just...

Easy way to use variables of enum types as string in C?

Here's what I am trying to do: typedef enum { ONE, TWO, THREE } Numbers; I am trying to write a function that would do a switch case similar to the following: char num_str[10]; int process_numbers_str(Numbers num) { switch(num) { case ONE: case TWO: case THREE: { strcpy(num_str, num); //some way to get the ...

Multithreaded Memory Allocators for C/C++

Hi I currently have heavily multithreaded server application, and I'm shopping around for a good multithreaded memory allocator. So far I'm torn between: -Sun's umem -Google's tcmalloc -Intel's threading building blocks allocator -Emery Berger's hoard From what I've found hoard might be the fastest, but I hadn't heard of it before ...

CScrollView and window size

(MFC Question) What's the best way to determine the current displayed client area in a CScrollView? I only need the size of the visible portion, so GetClientRect() won't work here. ...

Visual Studio 6 tips and tricks

Some of us would invariably have to support 'legacy' code using Microsoft's Visual Studio 6.0 IDEs which - although opinions would differ - are generally regarded to be less user friendly compared to the later incarnations of the Visual Studio series of IDEs. So I'd like to hear about some of your favourite hidden/poorly documented IDE ...

How does this C++ function use memoization?

#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return -2; if(as.size()<n+1) as.resize(n+1); if(as[n]<=0) { as[n]=-4*a(n-1)-4*a(n-2); } return mod(as[n], 65535); } The above code sample using memoization to calculate a recursive formula based on some input n. I know t...

Options for refactoring bits of code away from native C++?

So, one commonly heard comment when talking about performance is that you write your code with whatever language gets the job done fastest. If performance in specific areas is a problem, then rewrite those bits in C/C++. But, what if you're starting with a native C++ app? What options do you have if you want to write the easy bits, or r...

Using boost::random as the RNG for std::random_shuffle

I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from this shared state so that they can be deterministic with respect to the mersenne twister's previously generated numbers. I tried something like this: void foo(std::ve...

Will the below code cause memory leak in c++

class base{ int a; int *pint; someclass objsomeclass; someclass* psomeclass; public: base(){ objsomeclass = someclass(); psomeclass = new someclass(); pint = new int(); throw "constructor failed"; a = 43; } } main(){ base temp(); } in the above code constructor...

Linux configuration file libraries

Are there any good configuration file reading libraries for C\C++ that can be used for applications written on the linux platform. I would like to have a simple configuration file for my application. At best i would like to steer clear of XML files that might potentially confuse users. ...

Can you create collapsible #Region like scopes in C++ within VS 2008?

I miss it so much (used it a lot in C#). can you do it in C++? ...

Algorithm for finding the maximum difference in an array of numbers

I have an array of a few million numbers. double* const data = new double (3600000); I need to iterate through the array and find the range (the largest value in the array minus the smallest value). However, there is a catch. I only want to find the range where the smallest and largest values are within 1,000 samples of each other. S...

Why is my parameter passed by reference not modified within the function ?

I have got a C function in a static library, let's call it A, with the following interface : int A(unsigned int a, unsigned long long b, unsigned int *y, unsigned char *z); This function will change the value of y an z (this is for sure). I use it from within a dynamic C++ library, using extern "C". Now, here is what stune me : y ...

Problem using large binary segment in OOXML

System Description A plotting component that uses OOXML to generate a document. Plotting component consists of several parts. All parts are written in C++ as exe + dll's, with the exception of the interface to the OOXML document. The latter component is a COM component that was created in C#/.NET. The main reason for this is that the...

How to extract four unsigned short ints from one long long int?

Suppose I have one long long int and want to take its bits and construct four unsigned short ints out of it. Particular order doesn't matter much here. I generally know that I need to shift bits and truncate to the size of unsigned short int. But I think I may make some weird mistake somewhere, so I ask. ...

Eclipse C++ pretty printing?

The output we get when printing C++ sources from Eclipse is rather ugly. Is there are way/a plugin to pretty print C++ source code like e.g. with a2ps (which is probably using yet another filter for C source code)? ...