I see a lot of templates and complicated data structures for implementing a circular buffer.
How do I code a simple integer circular buffer for 5 numbers?
I'm thinking in C is the most straightforward?
Thanks.
...
i am trying to implement hash_multimap in c++ here is code
#include <hash_map>
#include<iostream>
#include <string>
#include <hashtable.h>
#include <hash_set>
#include <stdlib.h>
#include <stdio.h>
struct eqstr{
bool operator()(const char *s1,const char* s2)const{
return strcmp(s1,s2)==0;
}
};
typedef hash_multima...
Currently I use something like:
#include <sys/stat.h>
#include "My_Class.h"
void My_Class::my_function(void)
{
std::ofstream my_file;
struct stat file_info;
if ( filename_str.compare("")!=0 &&
stat(filename_str.c_str(),&file_info) == 0 )
{
my_file.open(filename_str.data(),std::ios::trunc);
//do stuff
my_...
Hey all,
I have a state machine design that needs to support playback. We have states that perform actions and sometimes need to generate random numbers. In case the program shuts down while in the middle of the FSM's execution, the program needs to playback the whole FSM using the same random numbers as before.
For a basic example, le...
I am pretty new to scipting languages (Perl in particular), and most of the code I write is an unconscious effort to convert C code to Perl.
Reading about Perl, one of the things that is often mentioned as the biggest difference is that Perl is a dynamic language. So, it can do stuff at runtime that the other languages (static ones) ...
I want to know how I can compile a C++ program with Xcode 3.2.3? In the previous version of Xcode, there was a C++ tool available for command line utility. However, after I upgraded to the latest version of Xcode 3.2.3, these options are gone.
...
I am trying to develop a C++ application. Part of the Application is meant to create and initiate some properties of an Object and then store the object in a multi-dimensional array. Problem is after Object creation and storing the objects in the array, retrieving the Object values gives me pointers to NULL.
Please see code below for ex...
I am porting some code from linux to windows and am coming up with some strange error. I have the following class:
(header)
RegionRectangle.h
#ifndef __RECTANGLE_H__
#define __RECTANGLE_H__
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle(int x = 0,int y = 0,int width = 0,int height = 0, int threshold=...
I'm wondering if it's possible to determine if a given address is on the stack or in the heap. I'd like this because a reference counting system we use has a flaw that if a smart pointer is somehow pointed at an object on the stack, bad things can happen. If I had this functionality, I could use it to detect this error condition early an...
IE what happens if you have this following piece of code?
int mean(const vector<int> & data) {
int res = 0;
for(size_t i = 0; i< data.size(); i++) {
res += data[i];
}
return res/data.size();
}
vector<int> makeRandomData() {
vector<int> stuff;
int numInts = rand()%100;
for(int i = 0; i< numInts; i++) {
stuff.push_b...
I do not know how to disable the web pages cache in my application which embed a Web Browser thanks to MSHTML.
I have googled it... MSDNed it... But still not able to find an answer...
Does someone know how to do it ?
Thanks in advance for all you answers.
EDIT : I now catch the DISPID_AMBIENT_DLCONTROL event in my Invoke() function.
...
Hi!
I want to ask, does C++0x going to provide delegate ?
If no, tell me what is the best way (most efficient) to use delegation in C++ ? Boost.Signals ? FastDelegate ? Or something other?
...
I've got this logging system for which I'm looking to shortcut some of the string manipulation.
The logging system is used via functional macros which then forward to a single function call. E.g. #define Warning(...) LogMessage(eWarning, __VA_ARGS__);.
LogMessage then does a snprintf into a new buffer and then presents that message to...
I would like to start my question by stating that this is a C++ design question, more then anything, limiting the scope of the discussion to what is accomplishable in that language.
Let us pretend that I am working on a vehicle simulator that is intended to model modern highway systems. As part of this simulation, entities will be inter...
Is there any existing iterator implementation (perhaps in boost) which implement some sort of flattening iterator?
For example:
unordered_set<vector<int> > s;
s.insert(vector<int>());
s.insert({1,2,3,4,5});
s.insert({6,7,8});
s.insert({9,10,11,12});
flattening_iterator<unordered_set<vector<int> >::iterator> it( ... ), end( ... );
for...
Especially for large scale projects where maintainability is important.
Explanations, links/references are also welcome.
...
I'm trying to replce some letter with the below code.
But, the result shows "ANULL" not "A"... How can I remove the NULL space...
ps. I'm modifying binary file information.
char *pos = NULL;
if(NULL != (posFind = strstr(fp, "AB");
strncpy(&fp->base[0], "A", 2);
if(_fseek64(fp, 0, SEEK_SET)!= 0) return ZD_ERROR_IO_FAILED;
fwrite(&f...
I want to do make a public member in a base class private in a derived class, like this:
class A {
public:
int x;
int y;
};
class B : public A {
// x is still public
private:
// y is now private
using y;
};
But apparently "using" can't be used that way. Is there any way to do this in C++?
(I can't use private...
I want to serialize a hash map to a file and de-serialize it later on.
#include <boost/serialization/hash_map.hpp>
#include <boost/filesystem/fstream.hpp>
#include <hash_map>
class A: virtual public B {
public:
friend class boost::serialization::access;
stdext::hash_map<std::string, myClass> myClassHashTable;
template ...
I used the Wizard to create a baisc input box with a OK and Cancel
I made the input box type "int" with min value 0 and max 99.
Now I want to edit the input box so that it is type string.
I have the MFC ClassWizard open and can see the ControlID, Type, and Member ID of the input box. However, there is no option to edit it...
How...