c++

How can I abstract out a repeating try catch pattern in C++

I have a pattern that repeats for several member functions that looks like this: int myClass::abstract_one(int sig1) { try { return _original->abstract_one(sig1); } catch (std::exception& err) { handleException(err); } catch (...) { handleException(); } } bool myClass::abstract_two(int sig2) { try { return _or...

error while loading shared libraries: libCstd.so.1: cannot open shared object file: No such file or directory

error while loading shared libraries: libCstd.so.1: cannot open shared object file: No such file or directory. Hello! I got this error when I tried to run a C++ project in Netbeans 6.8 with the Sun compiler from Sun Studio 12.1. I want analyze memory leaks and memory usage with dbx or the NetBeans IDE if it retrieves needed information....

supplying inputs to stdin programatically line by line ?

I have a test program which prompts for input from user(stdin), and depending on inputs, it asks for other inputs, which also need to be entered. is there a way I can have a script do all this work ? ...

c++ repaint part of window

i know how to repaint the full window but i don't know how to repaint a pieace of window like i draw a squre using gdi+ than i want to change it's coordinates so i want to repaint the squre not the whole window anyidea? i also tried this RECT rect2; rect2.left=0; rect2.top=100; rect2.right=225; rect2.bottom=300; InvadiateRect(hwnd, &...

Syntax for pointer to portion of multi-dimensional statically-allocated array

Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to get a pointer to a portion of it and use that pointer to access the rest of it. Basically, I'd like to be able to do something like this: #include <stdio.h> #include <string.h> #define DIM1 4 #define DIM2 4 #define DIM3 8 #define DIM4 64 static...

How to find the size of the hash table?

Hi, I've a hash table defined like this typedef std::unordered_map<unsigned long long int,unsigned long long int> table_map; and in the program, I read the contents of the a file into a buffer using fread like this: fread(buffer, sizeof(long long int), 1024, file1); I declare the hash table as table_map c1; Now i create a hash...

Is there a way to clear the buffer element by element?

Hi, I've a fread line in my code that reads the contents of the file like this fread(buffer,sizeof(char),1024,file1); I kow that I can free the buffer using free(buffer); but my questions is, is there a way to delete the elements in the buffer one by one?. Say, I used the first element and I no longer need it so I want to delete it...

visual c++ 2010 debugging problem

When I debug the my game, it works. But if I open my game's exe file that is stored in my project debug file, it shows as being 3 days old. The file is not getting updated. Any ideas why? ...

How to release the memory of structures pointed by an pointer-array?

I have a pointer array defined as some_struct * t_ptr[1000] which points to a structure some_struct.And some points of the point array are evaluated.e.g some_struct * wpaper1 = new some_struct(); //memory leaks detected in this line wpaper1->tAnswer = useransw; wpaper1->tKey = key; t_ptr[100] = wpaper1; //there're wpaper2,wpaper3....

How to open a file when file handle number is known?

I open a file in C# with FileStream, and I got the file handle number with this line: IntPtr file_handle = fs.SafeFileHandle.DangerousGetHandle(); Now I want to pass this handle to C++ code and use this handle value to access the file. Is this possible? How to open a file with merely a file handle in C++? Thanks. Update I use C# to...

copying a subvector

Hi, I want to divide my array of n elements and copy it into a vector in two halve (0 to n/2 , n/2 to n). What is the easiest way of doing this ? ...

How do I send long PUT data in libcurl without using file pointers?

I'm trying to interface with the Google Contact API, and in order to update a contact on the remote side, I need to use a PUT request instead of POST. Since the data I want to PUT is already in memory, I really don't want to deal with file pointers, which seems to be the default behavior of CURLOPT_READDATA. Thus, I understand I need to...

Moving from C# to C++

I'm a slightly-below average programmer in C#, and I only write apps with GUIs. I might be getting a Mac soon. Since there isn't the .NET Framework or Visual Studio on Mac, I'm going to be using Xcode and Cocoa. I think this will be a good opportunity to switch to a well known and well supported language (C++). I learned C# very easily w...

c++ high cpu usage

Possible Duplicate: c++ using too much cpu my game uses over 50% of cpu. i found way to reduce the cpu to be 40-50% but i can't find any other way to reduce it. i tried to use Code analyst profiler but it doesn't give me any good information in my code where im using my cpu. here is my code // Xstrike.cpp : Defines the entr...

What detectable differences are there between a class and its base-class?

Given the following template: template <typename T> class wrapper : public T {}; What visible differences in interface or behaviour are there between an object of type Foo and an object of type wrapper<Foo>? I'm already aware of one: wrapper<Foo> only has a nullary constructor, copy constructor and assignment operator (and it only ...

How to initialize bitfields with a C++ Constructor?

First off, I’m not concerned with portability, and can safely assume that the endianness will not change. Assuming I read a hardware register value, I would like to overlay that register value over bitfields so that I can refer to the individual fields in the register without using bit masks. EDIT: Fixed problems pointed out by GMan, an...

c++ return value

hi, I have the following code in c++: int fff ( int a , int b ) { if (a>b ) return 0; else a+b ; } although I didn't write 'return' after else it does not make error ! < br/> in main() when I wrote: cout<<fff(1,2); it printed 1 ? How did that happened can any one Explain that ? ...

problem with merge sort

void merge(vector<int> dst,vector<int> first,vector<int> second) { int i=0,j=0; while(i<first.size()&&j<second.size()) { if(first[i]<second[j]) { dst.push_back(first[i]); i++; } else { dst.push_back(second[j]); j++; } } wh...

Variadic macros with zero arguments, and commas

Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero arguments it produces bad code since the compiler expects an identifier after the comma. Actually, VC's preprocessor is smart enough to remove the comma, but GCC's isn't. Since macros can't be overloaded, it seems like it takes a se...

C++: How to check if a file/directory is readable? (PHP equivalent: is_readable)

I am trying to validate a directory with C++. http://php.net/manual/en/function.is-readable.php bool is_readable ( string $filename ) Tells whether a file (or directroy) exists and is readable. What would be the equivalent of the above in C++? I am already using the boost/filesystem library to check that the directory exists. I ha...