c++

Copying from istream never stops

This bit of code runs infinitely: copy(istream_iterator<char>(cin), istream_iterator<char>(), back_inserter(buff)); The behavior I was expecting is that it will stop when I press enter. However it doesn't. buff is a vector of chars. ...

Why do bind1st and bind2nd require constant function objects?

So, I was writing a C++ program which would allow me to take control of the entire world. I was all done writing the final translation unit, but I got an error: error C3848: expression having type 'const `anonymous-namespace'::ElementAccumulator<T,BinaryFunction>' would lose some const-volatile qualifiers in order to call 'void `anonymo...

Issues with HLSL and lighting

I am trying figure out whats going on with my HLSL code but I have no way of debugging it cause C++ gives off no errors. The application just closes when I run it. I am trying to add lighting to a 3d plane I made. below is my HLSL. The problem consist when my Pixel shader method returns the struct "outColor" . If I change the return valu...

Binary search to find the rotation point in a rotated sorted list

I am having a sorted list which is rotated and I would like to do a binary search on that list to find the minimum element. Lets suppose initial list is {1,2,3,4,5,6,7,8} rotated list can be like {5,6,7,8,1,2,3,4} Normal binary search doesn't work in this case. Any idea how to do this. -- Edit I have one another condition. What if th...

Connecting C++ backend to Javascript

I was hoping to make a website that displays a google map with points based of information returned by a C++ function. I know you can use Java Server Pages to call java methods on the server with javascript. Would there be a way to connect C++ code on the server with javascript in order to produce the same result as java server pages? ...

What the best multi-thread application debugger for C++ apps.

I'm looking for a good multi-thread-aware debugger, capable of showing performance charts of application threads on Linux, don't know if such a thing exists, perhaps as a Eclipse plugin. The idea would be to track per thread memory allocation a CPU usage as well as being able to interrupt a thread and examine its stack trace, local vars,...

copying a substring from a string given end index in string

Hi, How can i copy a substring from a given string with start and end index or giving the start index and length of the string are given. Thanks, iSight ...

Newbie question: When to use extern "C" { //code } ?

Hello, Maybe I'm not understanding the differences between C and C++, but when and why do we need to use: extern "C" { ? Apparently its a "linkage convention"? I read about it briefly and noticed that all the .h header files included with MSVS surround their code with it. What type of code exactly is "C code" and NOT "C++ code"? I ...

searching a character in a string

Hi, How can i search a character " in a string. ...

`.' cannot appear in a constant-expression

I'm getting the following error: `.' cannot appear in a constant-expression for this function (line 4): bool Covers(const Region<C,V,D>& other) const { const Region& me = *this; for (unsigned d = 0; d < D; d++) { if (me[d].min > other[d].min || me[d].max < other[d].max) { return false; ...

glFog causing transparent png to lose transparency

Without glFog, my transparent png displays fine, but with it you can see the rectanglular background and strips of other colours (notice the other dirt material is working as intended, but not using a png or transparency). Here's my code for the fog: GLfloat colour[4]={0.8f,0.8f,1.0f, 1.0f}; glFogi(GL_FOG_MODE, GL_EXP); glFogfv(GL_FO...

Why can't I reserve 1,000,000,000 in my vector ?

When I type in the foll. code, I get the output as 1073741823. #include <iostream> #include <vector> using namespace std; int main() { vector <int> v; cout<<v.max_size(); return 0; } However when I try to resize the vector to 1,000,000,000, by v.resize(1000000000); the program stops executing. How can I enable the program to all...

Reading and writing to files simultaneously?

Moved the question here. Suppose, I want to store 1,000,000,000 integers and cannot use my memory. I would use a file(which can easily handle so much data ). How can I let it read and write and the same time. Using fstream file("file.txt', ios::out | ios::in ); doesn't create a file, in the first place. But supposing the file exists, I a...

Higher order function « filter » in C++

Hi all. I wanted to write a higher order function filter with C++. The code I have come up with so far is as follows: #include <iostream> #include <string> #include <functional> #include <algorithm> #include <vector> #include <list> #include <iterator> using namespace std; bool isOdd(int const i) { return i % 2 != 0; } template < ...

How union is used to define a class

Hi, I have two doubts, please help me on this: Is it possible to define a class inside union Is it possible to define a class without class name ...

how to pass vector objects from one class to another

This is how I had tried sending the vector using one of the answers I got., but has not worked out yet.Should copy whn it gets to auctioneer.I want to display. class Trader { private: int nextBidId; public: void loadRange( vector <Bid> & bids ) {} ; class Simulator //Receives from the Trader,doent modify { ...

Win32 Thread Exits Unexpectedly

Hello, I'm writing a C++ application. I realized that one of my worker threads may terminate unexpectedly. The (VS 2005) debug log says: The thread 'Win32 Thread' (0x5d98) has exited with code -858993460 (0xcccccccc). I surrounded all the worker thread code with a try/catch block. So, if the reason was an exception, I would cat...

Recursive and inline functions in c++

Can anyone tell me the main difference between an inline function and recursive function? ...

C callback functions defined in an unnamed namespace?

Hi all. I have a C++ project that uses a C bison parser. The C parser uses a struct of function pointers to call functions that create proper AST nodes when productions are reduced by bison: typedef void Node; struct Actions { Node *(*newIntLit)(int val); Node *(*newAsgnExpr)(Node *left, Node *right); /* ... */ }; Now, in the C+...

Singleton with inheritance, Derived class is not able to get instantiated in parent?

Below code instantiates a derived singleton object based on environment variable. The compiler errors saying error C2512: 'Dotted' : no appropriate default constructor. I don't understand what the compiler is complaining about. EDIT: Fixed issues with implementing the get instance method which requires definition of both the parent and ...