c++

c++ string allocation

do I need to take care of memory allocation, scope and deletion about c++ "string" object? for example: #include <string> const char* func3() { string s = "this is a literal string"; return s.c_str(); } string func2() { string s = "this is a literal string"; return s; } const char* func1() { const char* s = "this is a...

first n digits of an exponentiation

How do i determine the first n digits of an exponentiation (ab). eg: for a = 12, b = 13 & n = 4, the first 4 digits are 1069. ...

Are System.out, stdout and cout the exact same thing ?

Are System.out, stdout and cout the EXACT same thing in Java, C and C++ respectively? Why have three different names for the same thing (especially when C, C++ and Java have much in common)? Also, I know what they are used for but what are they exactly, under the hood, I mean? ...

C++ header issue

So I essentially have the following code. I had working code and wanted to separate some of it into two different classes, D3DWindow and D3DController, rather than having it all in D3DWindow. I don't believe it is a pch problem because it was working prior to the separation. The problem occurs in D3DController.cpp. It says something alon...

I need C++ array class template, which is fixed-size, stack-based and doesn't require default constructor

So, I've been looking at boost::array but it does require default constructor defined. I think the best way of filling this array with data, would be through a push_back(const T&) method. Calling it more times than SIZE (known at compile-time) would result in assert or exception, depending on build configuration. This way it would always...

C++ Misfeatures Based on Experience

Recently a colleague asked my opinion on the use of exception specifications in C++ code, and I was able to dredge up this article by Herb Sutter: A Pragmatic Look at Exception Specifications. The article, like most by Herb Sutter, is an educational read, but the short answer is "don't do that." In the summary, he makes reference to a p...

boost unique_ptr Deletor

If I want to create a unique_ptr of type QueueList (some self defined object), how do I define a deletor for it or is there already a template 'Deletor' I can use? I want a unique_ptr so I can safely transfer the object between threads, without sharing it between the threads. EDIT boost::interprocess::unique_ptr<QueueList> LIST; ///F...

What are Containers/Adapters? C++

What are containers/adapters? Someone please explain in layman's language. I have tried to look up on the internet but the definitions and explanations are too technical and hard to understand. I have basic knowledge of C++ and its sub-topics like (class/templates/STL). EDIT 1: Can anyone please give me a practical example of the ap...

Is there a known bug in Visual Studio 2008 for using drop target in C++ when running Visual Studio as administrator?

We have an application that allows a user to drag a picture to a window and that window is a drop target (using OLE). When this code is run in the debugger and the Visual Studio instance is run as administrator (right click from desktop) then the target drop is not allowed. If the exe is run on its own it works fine. If the visual stu...

Netbeans fails to execute perl script when compiling C++ project

I installed Netbeans 6.9.1 with C++ support. I also installed MinGW. When I create a C++ project and run it, I get this: I checked the c++ configuration in Netbeans: (looks good) Perl is installed on my PC under c:\perl I tried reinstalling Netbeans and I tried removing Netbeans and Perl then reinstalled Netbeans. It didn't work ...

MASM str and substr?

Hello everybody, I'm currently coding an irc bot in asm I have already done this once in C++, so I know how to solve most problems I encounter, but I need a substr()[*] function like the one seen in C++. I need the substr fucntion to receive the server name from a PING request so I can respond with the corresponding PONG response But I ...

Detecting the use of HRESULTs as bools

We have a big body of code that was refactored so that stuff which was plain-old C++ is now COM. I've been spending the last couple of days hunting out places in which we missed the fact that a function that previously returned a bool now returns an HRESULT (the problem is compound by the fact that S_OK == false). Is there a way to det...

How do I get LWP using Linux glibc ?

I developed a process with some threads on a Linux machine (Ubuntu). I'd like to know how can i get LWP from each thread (using a glibc function), once the PID and PPID are always the same for all the threads of the process. UID PID PPID LWP C NLWP STIME TTY TIME CMD root 2588 2587 2588 0 11 00:05 ? ...

Passing an object to a function taking pointer as parameter

How does it work when I only have an object but my function takes a pointer to that type of object. Someoclass test1; SomeFunction( Someclass*) { //does something }; ...

Some questions about floating points

I'm wondering if a number is represented one way in a floating point representation, is it going to be represented in the same way in a representation that has a larger size. That is, if a number has a particular representation as a float, will it have the same representation if that float is cast to a double and then still the same when...

Placement new issue

In this http://stackoverflow.com/questions/3873625/i-need-c-array-class-template-which-is-fixed-size-stack-based-and-doesnt-req/3873706#3873706 answer I posted a piece of code, that is using placement new with char array. For me, this is something absolutely normal. But according to comments this code is wrong. Can anyone explain in mor...

why std::queue doesn't support clear() function ?

Hi, I have requirement like this. For a function, i get input as a stream of numbers. I mean, function keeps on getting called with single number in each call. I am using queue for storing stream of numbers. I need to process a collected set of numbers only when some condition is satisfied. If condition is not satisfied i need to throw...

vector.h or vector.. neither works!

if I put: #include vector.h I get this annoying warning. make -f Makefile CFG=Debug g++ -c -g -o "Debug/mynn.o" "mynn.cpp" In file included from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/backward/vector.h:59, from mynn.h:7, from mynn.cpp:1: **C:/MinGW/bin/../lib/gcc/mingw...

Is this usage of unordered map efficient/right way?

I want to learn about mapping functions in c/c++ in general so this is a basic program on unordered mapping. I use unordered mapping because my input data are not sorted and I read that unordered_map is very efficient. Here I've an array with which I'm creating the hash table and use the lookup function to find if the elements in another...

What is a good project for starters with some actual use

I wont call myself a novice programmer, I have been working for a while now in c and c++ however I have never worked on something of my own. I think a bigger learning can be accomplished if one works on some project on there own apart from there work. Keeping this in mind, could you guys tell me some project I can implement? I recently l...