c++

Solving aliasing problem in c++

I was trying following code in which I defined copy c'tor explicitly to solve aliasing problem. But code is giving runtime error. #include<iostream> #include<cstring> using namespace std; class word { public: word(const char *s) // No default c'tor { str=const_cast<char*>(s); cnt=strlen(s); } word(const ...

Check password before decryption.

I'm writing small program (C++) to encrypt/decrypt files. Before decryption I would like to check if password given by user is correct. My idea: Add at the beginning of file some string (for example: "GOOD"); Encrypt file When decrypting first decrypt the beginning of file and check for "GOOD" string Is this correct? ...

GetVolumePathName() failed with ERROR 158: ERROR_NOT_LOCKED

GetVolumePathName() API failed and GetLastError() returned ERROR 158: ERROR_NOT_LOCKED. What is the reason for this error and how to overcome it? ...

checking data availability before calling std::getline

Hi All I would like to read some data from a stream I have using std::getline. Below a sample using the std::cin. std::string line; std::getline( std::cin, line ); This is a blocking function i.e. if there is no data or line to read it blocks execution. Do you know if exists a function for checking data availability before calling s...

Are there any code analysis tools that will make my job easier?

I have recently inherited a program written in Managed C++ from some guy who just retired. After spending some time digging through it, I can honestly say that at least 95% of it belongs on thedailywtf. However, I am now tasked with modifying it and porting it over to a language I'm comfortable with. The program itself takes in many m...

struct as key of unordered_map

Hi, I have a problem putting data into an unordered_map using a struct as key: typedef struct osdpi_flow_identificator { u32 lower_ip; u32 upper_ip; u16 lower_port; u16 upper_port; u8 protocol; } osdpi_flow_identificator_t; // custom hash function for osdpi_flow_identificator struct osdpi_flow_hash { std::size_t operator() (osd...

linked list from java to c++

here is code to implement linked list i hope you understand main purpose of this code such kind of code is written in java and i am trying to implement in c++ #include <iostream> using namespace std; class link { public: int idata; double ddata; link ( int id,double dd){ idata=id; ddata=dd; } public : ...

glBufferData fails silently with overly large sizes

hi everybody, i just noticed, that glBufferData fails silently when i try to call it with size: 1085859108 and data: NULL. Following calls to glBufferSubData fail with a OUT_OF_MEMORY 'Exception'. This is on Windows XP 32bit, NVIDIA Gforce 9500 GT (1024MB) and 195.62 Drivers. Is there any way to determinate if a buffer was created suc...

Returning values from pthread asynchronously at regular intervals

Hi, The main() function creates a thread that is supposed to live until the user wishes to exit the program. The thread needs to return values to the main functions at periodic intervals. I tried doing something like this, but hasn't worked well - std::queue<std::string> q; void start_thread(int num) { std::string str; //Do some pro...

Do inline functions have addresses?

In section 7.1.1 of the book "The C++ Programming Language" the author states: "inline function still has a unique address and so do the static variables of an inline function" I am confused. If I have an inline function then it can't have address. Does this happen in C also? ...

#pragma pack effect

I was wondering if someone could explain to me what the #pragma pack preprocessor statement does and more importantly why one would want to use it. I checked out the msdn on this http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx, which offered some insight, but I was hoping to hear more from people with experience. I've seen i...

full code from java in c++

here is full code from algorithm and data structure in java written in c++ #include <iostream> using namespace std; class link { public: int idata; double ddata; link *next; link ( int id,double dd){ idata=id; ddata=dd; } public : void display(){ cout<<idata<<"=>"; cout<<ddata;...

Win32 API stack walk with MinGW/MSYS?

Hi all, i've to develop a stack trace walk to our win32 API plattform support to catch any exception with a behaviour of a JAVA stacktrace. Actually we got a full functional implementation for Linux plattforms. First i've tried to implement a stackwalk using the win32 CaptureStackBackTrace API mechanism. But this method is not integrat...

how does GlPolygonStipple's mask parameter work?

I can't find a tutorial showing me how this works and I don't get it. I'd like to use it to draw dashed lines since I have an algorithm that generates triangles and would like it to skip some after a certain distance has been reach (a bit like glLineStipple) Thanks ...

Check if ostream object is cout or ofstream, c++

Is there a way in C++ to check if an ostream object is cout or a ofstream object? Something like: ostream& output(ostream& out) { if (out == cout) return out; else { out << "something different because its not going to the console" << endl; return out; } } The reason I want to do this, is that ...

Looking for an easy to use embedded key-value store for C++

I need to write a C++ application that reads and writes large amounts of data (more than the available RAM) but always in a sequential way. In order to keep the data in a future proof and easy to document way I use Protocol Buffer. Protocol buffer however does not handle large amounts of data. My previous solution consisted on creating...

Why is c++ that powerful concerning game development?

I was just wondering why c++ ist that powerful and performant for developing games. I wrote a lot of games in c# and delphi, always using the timer component to make objects "move". Another option for the movement were loops, but they are definitely not performant. So what technique does c++ use that users can develop performant games? ...

g++ duplicate symbol error when working with templates (noob question)

Hi, So I'm trying to pick C++, and to do so I decided to write a generic Group class using templates, that takes a Type and size as template parameters: in group.h: #ifndef __GROUP_H #define __GROUP_H #define MAX_SIZE 10 /********************************************************** * Define a Group class that handles a collection of m...

Can derived class use friend function of the basis class?

Hello, If I have some class Basis, and derived from it Derived, inside basis I have friend function friend int operator!=(const Basis&, const Basis&) Inside derived class I don't have such function So my question is if I have inside my main If( derived1 != derived2 ) ... why does it work? i don't have any constructor for casting f...

How to serialize the GMP mpf type?

It seems that GMP provides only string serialization of the mpf (floating point) type: mpf_get_str(), mpf_class::get_str() The mpz (integer) type has an additional interface for raw bytes: mpz_out_raw() http://gmplib.org/manual/Function-Index.html Am I missing something? Does anyone know of another library that can serialize GMP flo...