c++

Exercise Self Study Help

I've started learning C++ and am working through some exercises in the C++ Primer Plus book. In chapter 5 one of the exercises is: Write a program that uses an array of char and a loop to read one word at a time until the word done is entered. The program should then report the number of words entered (not counting done)....

replace whitespace in an string c++ boost problem

hello i am using this code to replace the while space but it never replaces all the white space can u please tell me where i am wrong #include <iostream> #include <string> #include <boost/regex.hpp> #include<boost/algorithm/string.hpp> #include<boost/algorithm/string/replace.hpp> using namespace std; int main(void) { string...

Set Individual Pixels on Back Buffer

I want to be able to set the individual pixels of the back buffer in my program in an efficient way. This is what I call in my rendering function: void render_frame(void) { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); d3ddev->BeginScene(); d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO,...

What can be a reason for making some class-specific functionality a separate function instead of member function?

While reviewing rather old code I found some strange design decision: // irrelevant stuff removed class Class { public: int GetStage() const { return stage; } void SetStage( int value ) { stage = value; } private: int stage; }; void ProgressStage( Class* object ) { int stage = object->GetStage(); assert( stage < MaxSta...

Storing boost function

Hello, I have to store a list of different boost::function objects. To provide this I'm using boost::any. I have a few functions which takes different functions signatures, pack them into any and then insert into special map with given type. Here is the code: enum TypeEnumerator { e_int, e_float, e_double }; typedef map< st...

Multicasting in C++ : Error "An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call"

Hi, I have developed one server pgm for multicasting in C++, when i register the address and after that when i set the socket option using setsockopt it returns me -1 If this option is not supported in setsockopt then how i can go for multicasting in C++ My code is below : #include"winsock.h" #include<iostream> #include<conio.h> usi...

cant make sense of LARGE_INTEGER struct

Hello fellow SOers, I'm asking this mainly out of curiousity. I am not really a C(++) Coder but to widen my horizon I try to dive in other areas every now and then. When doing this with C++ and some Winapi things, I encountered this guy: #if defined(MIDL_PASS) typedef struct _LARGE_INTEGER { #else // MIDL_PASS typedef union _LARGE_INTE...

How to Send a structure using sendto()

I have created structure : struct buffer { string ProjectName ; string ProjectID ; } buffer buf; buf.ProjectID = "212"; buf.ProjectName = "MyProj"; Now to send this structure using sendto method , I am typecasting the strucure and sending it back as below: char *sendbuf = (char*)&buf; sentbytes = sendto(sock,sendbuf,strlen(s...

Unnamed classes

Motivated by the discussion The grammar for C++ classes is defined as class-key identifier *[opt]* base-clause *[opt]* (Italics are mine) This to me means that the class name is option and we can have unnamed classes in C++. So, is the following well-formed? struct X{ struct{ int x; int y; }; }; int main(){} ...

Choice of the most performant container (array)

This is my little big question about containers, in particular, arrays. I am writing a physics code that mainly manipulates a big (> 1 000 000) set of "particles" (with 6 double coordinates each). I am looking for the best way (in term of performance) to implement a class that will contain a container for these data and that will provid...

Why won't this compile (link) with the Q_OBJECT macro in place?

Hi, I made a prototype of a project with PyQt and made it work there, now I'm trying to convert it to C++ and am having some problems. If I don't put the Q_OBJECT macro in, it compiles and works, but if I comment it out, I get the following errors: Undefined symbols: "vtable for MapView", referenced from: MapView::~MapView()in...

Using a lib with enabled exception handling in an application where exception handling is turned off

Hi all, This question is about a C++ library for Windows and we use Visual C++ as our compiler. We enable exception handling compiler option in our library. We also use throw/catch in a few places. One of our customers says that they disable exception handling option in their application. Now the question is, whether they would exper...

struct with 2 cells vs std::pair ?

Possible Duplicate: What is the difference between using a struct with two fields and a pair? Dear all, I have a little question about pairs and struct. Is there any advantage to use a std::pair instead of a struct with two cells ? I have used pairs for a while but the main problem is readability : If you want to represent fo...

how to destroy stl Queue created on heap?

As per req i have to create stl queue on heap i have created stl queue on heap in constructor of my class as per below code queue<int> *myqueue; myqueue=new queue<int>(); Now in destructor i want to destroy it: so i have written code while(!myqueue->empty()) { myqueue->pop(); } please tell me is it right way to destroy it or th...

Is there a standard way to convert from container<Type1> to container<Type2> ?

I have two classes A and B, and an implicit conversion operator exists to go from one to the other, so that: A a; B b; b = a; // Works Is there a standard way to convert a std::list<A> to a std::list<B> ? (Or even from std::vector<A> to a std::list<B>). I know I can iterate trough to the list and build the second list item by item, b...

Why Floating point numbers cant be compared?

Possible Duplicate: strange output in comparision of float with float literal #include<stdio.h> int main() { float me = 1.7; if(me==1.7) printf("C"); else printf("C++"); } Output: C++ Now the reason for this behaviour is said that many floating point numbers cant be represented with absolute precision in binary. My...

How to get started implementing a video streaming server in c/c++?

In my project I need a dedicated server that dispatches the streams over to multiple clients. More specificly, I've a callback function that gets called to gather the stream data, but no idea how to stream it over to other applications. What's the best way to get started on this ? ...

error C2440: '=' : cannot convert from 'char [5]' to 'char [20]'

This is linked to my previous post Wher I created a Struct : struct buffer { char ProjectName[20]; char ProjectID[20]; }; Now while I am trying to assign values to it: buffer buf; buf.ProjectID = "3174"; buf.ProjectName = "NDS"; I am getting this error: error C2440: '=' : cannot convert from 'char [5]' to 'char [20]' ...

How could I link my c++ console application to take control of an existing console?

How would I take control of the console of a batch file, and load it into my c++ application? ...

Function specifier

virtual and inline are function specifier. They can appear before function only.{as per my understanding}. Then,In following code what is virtual? class Base { // }; class Derived :virtual public Base { }; ...