I am new to C++ and still juggling with stringstream.
I have written a small piece of code which doesn't give required output
The code is as follows:
#include "iostream"
#include "sstream"
using namespace std;
int main ()
{
string xyz;
cout << "Initial xyz : " << xyz << endl;
stringstream s1 ( xyz );
s1 << "Hello";
cout ...
I've got a simple class called object that I'm having a problem with. Theres one method which causes a segfault if I call it. I don't understand why.
typedef class object
{
private:
short id;
std::string name;
SDL_Rect offset;
public:
object();
object(short i, std::string n);
~object();
o...
I'm trying to define an overload for the != operator. My code is as follows. (Update: outdated code. If one of two article pointers points to NULL, this code will crash.)
bool ArticleContainer::ArticleIterator::operator!=(const ArticleIterator& artit) {
if (this->article == NULL && artit.article == NULL)
return false;
el...
In code below (please see comment):
#include "stdafx.h"
#include <iostream>
using std::cout;
struct Base
{
void fnc()
{
cout << "Base::fnc()";
}
};
struct Impl
{
void* data_;
Impl(void (Base::*fp)())
{
fp();//HERE I'M INVOKING IT - I'M DOING SOMETHING WRONG!
}
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
...
I moved from Windows to Mac and now I'm experiencing a problem with the file input/output classes: ifstream & ofstream.
In Windows when you run with g++/Code Blocks
ofstream out("output.txt");
out << "TEST";
out.close();
A new file "output.txt" will be created in the same directory.
However in MAC OS X, this file is created in my h...
I am implementing a Go Back N protocol for a networking class. I am using WaitForSingleObject to know when the socket on my receiver thread has data inside it:
int result = WaitForSingleObject(dataReady, INFINITE);
For Go Back N, I have to send multiple packets to the receiver at once, and manipulate the data, and then send an ACK pac...
Hi experts,
Since std::pair<std::string, unsigned int> is not defined for __gnu_cxx hash map, how do I create a __gnu_cxx hash map with keys of type std::pair<std::string, unsigned int> and values of type std::pair<int, CBTNODE>? (CBTNODE is typedef as typedef int CBTNODE)
If it's possible, I would really want to substitute std::pair<...
int *p;
while(true)
{
p = new int;
}
Due to running out of memory space, shouldn't this code crash. I have tried printing out the value of p, that is the address of memory located for p, and it seems to increase yet there is no crashing.
Why is this so?
...
Hi.
I want to pass Resize method of my Foo class object as the argument of glutReshapeFunc() but I get that error.
How should I pass it?
This is my definition of Resize:
class Foo{
public:
void Resize(int w, int h);
...
}
and this is how I try to call it
glutReshapeFunc(foo->Resize);
It was ok when foo was not a pointe...
How do I get a reference to a "get"-function for a specific tuple instance?
My best try is given below but does not compile against g++4.5.1
#include <tuple>
#include <string>
typedef std::tuple<int,std::string> Tuple;
auto t=(std::string& (Tuple&))(std::get<1,Tuple>);
The compiler error is:
a.cc:5: error: invalid cast to function ...
See title. I'm using Code::Blocks. Googling results in info involving the sdl-config sh script, which I obviously can't use on Windows.
...
Say I have a template class that takes msgs from source, does something smart to them, and then sends them to a sink:
template <typename Source, typename Sink>
class MsgHandler
{
MsgHandler(Source* pSource)
: m_pSource(pSource)
{
m_pSource->setHandler(this);
}
};
//Now the definition of the Source:
template <typename Handler>
class ...
I have a complex mathematical C++ function. I want a translated and easy to read graph out of it. Is there any software which can analyze special mathematical functions and draw an easy to read graph? Assume it's an encryption algorithm code.
I have tried a lot of software like Understand, WizGraph, etc. Is there something I should sea...
I occasionally use 64 bit arithmetic in an open source C++ library of mine. I discovered that long long serves my purpose quite nicely. Even some 10 year old solaris box could compile it. And it works without messing around with #defines on Windows too.
Now the issue is I get complaints from my users because they compile with GCC -pedan...
My application in working fine in Samsung BADA simulator but not working in device. My application is for S8500, available for download https://sourceforge.net/projects/wavechm/ with source code. I don't know what to do now?
...
is this possible to get all the variables and methods of a class at runtime?
if yes then how?
I did this in C# using Reflection. but now i am working in C++.
...
Hi all,
I am capturing video from my webcam and it is processed by a C# program then i want to stream it to a C++ program. this C++ program can be configured to get a video stream from a webcam so is it possible to send/stream my processed video to this program where the C++ program detect that stream as a video which is coming from the ...
I'm writing my own 3D engine and I have this matrix to make a perspective look. (It's a standard matrix so there is nothing interesting)
public static Matrix3D PrespectiveFromHV(double fieldOfViewY, double aspectRatio, double zNearPlane, double zFarPlane, double mod)
{
double height = 1.0 / Math.Tan(fieldOfViewY / 2.0);
...
I've created a simple test case exhibiting a strange behavior I've noticed in a larger code base I'm working on. This test case is below. I'm relying on the STL Map's "[ ]" operator to create a pointer to a struct in a map of such structs. In the test case below, the line...
TestStruct *thisTestStruct = &testStructMap["test"];
...gets...
When a expression is evaluated in C/C++, does it follow BODMAS [Bracket open Division Multiply Addition Substraction] rule? If not then how they are evaluated?
EDIT: More clearly, If the following expression is evaluated according to BODMAS rule,
(5 + 3)/8*9
First what is in brackets is processed.
8/8*9.
Then Division is done.
1*9...