c++

How to generate a guitar note

Back in a freshman or software programming class we had to write a program that would simulate the sound of a guitar pluck. I can make pure sin waves all day, but I am trying to remember how to do a sound like a guitar pluck. I remember it had something to with using random() and a falloff constant added to the sin wave, but I can not r...

How to I draw pixels as a texture to a polygon in OpenGL?

In C++ OpenGL, I want to draw each pixel manually (as a texture I assume) on to a simple square primitive, or indeed 2 polygons forming a square. I have no idea where to start, or what phrases to look for. Am I looking for texture mapping or creating textures? Most examples are to load from a file, but I dont want to do that. I've trie...

firefox cache hash key generation algorithm bug

There is a bug in Firefox (even in the new betas and in minefield releases) which prevents the caching of certain files because of the algorithm for creating a key in their cache hash. Here is a link to the source code of the function. I want to ensure that all of my site's files can be cached. However, I do not understand why their...

How the buffer of cout work?

I know that cout have buffer several days ago, and when I google it, it is said that the buffer is some like a stack and get the output of cout and printf from right to left, then put them out(to the console or file)from top to bottem. Like this, a = 1; b = 2; c = 3; cout<<a<<b<<c<<endl; buffer:|3|2|1|<- (take “<-” as a poniter) outp...

Redirecting standard output to syslog

Hi! I'm planning to package OpenTibia Server for Debian. One of the things I want to do is add startup via /etc/init.d and daemonization of the otserv process. Thing is, we should probably redirect output to syslog. This is usually done via the syslog() function. Currently, the code is swarmed with: std::cout << "Stuff to printout" <<...

Is stereoscopy (3D stereo) making a come back?

I'm working on a stereoscopy application in C++ and OpenGL (for medical image visualization). From what I understand, the technology was quite big news about 10 years ago but it seems to have died down since. Now, many companies seem to be investing in the technology... Including nVidia it would seem. Stereoscopy is also known as "3D St...

C++/QT: drawing a caret

I'm learning QT. I just started to write a text editor from scratch by inheriting QAbstractScrollArea. I'm doing this just for practice. But now I'm faced with the problem of displaying a caret. What comes to my mind is painter.drawLine and QTimer. Can you give some advices on this. I would also be glad hear some strategies to implement ...

Copy Constructor in C++ is called when object is returned from a function?

I understand copy constructor is called on three instances When instantiating one object and initializing it with values from another object (as in the example above). When passing an object by value. 3. When an object is returned from a function by value. I have question with no.3 if copy constructor is called when an object value...

Copy constructor vs. return value optimization

In a previous question, it appeared that a plain return-by-value function always copies its return argument into the variable being assigned from it. Is this required by the standard, or can the function be optimized by constructing the 'assigned to' variable even within the function body? struct C { int i; double d; }; C f( int i, in...

What component do I need to monitor my internet traffic on my PC?

I would like to be able to see and monitor my internet data (http/emule/email) on my own PC using Windows XP. I am thinking of something like WireShark but I would like to control it programmatically. I would be using C or C++. How can I do this? ...

static members and boost serialization

I'm using Boost.Serialization to archive the contents of a class. One of the member variables is a static std::vector. Archiving and restoring goes fine, but I was kind of hoping the library would save static members only once, it appears that, judging by the filesize, the static members are fully saved for each archived instance. This...

Problem with dereference operator and functions.

I have a function A(), that returns a pointer to an object. In function B() I try to change a member of that object in the following way: void B() { ObjType o = *getObj(); o.set("abc"); } Object o is stored in an array, and when I print the value of the member, it seems nothing happened, and the member still has the old value;...

Accessing public class memory from C++ using C

Greetings Everyone. I'm currently writing a multi-language programe in C, C++ and fortran on UNIX, unfortunatly I run into "Segmentation Error" when I try and execute after compiling. I've narrowed down the problem to the interface between the C++ and C sections of my program. The first section consists of main.ccp and SA.cpp, and the...

What is the correct way of reading from a TCP socket in C/C++?

Here's my code: // Not all headers are relevant to the code snippet. #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <cstdlib> #include <cstring> #include <unistd.h> char *buffer; stringstream readStream; bool readData = true; while (readData) { cout << "Receiving ...

Importing explicitly instantiated template class from dll.

Being a dll newbie I have to ask the allmighty SO about something. Say I explicitly instantiate a template class like this: template class __declspec(dllexport) B<int>; How do I use import this templated class again? I've tried the adding the code below in my .cpp file where I want to use B template class __declspec(dllimport) B<i...

Forcing my MFC app to run as Administrator on Vista

I have an MFC app built using Visual Studio 2008 and it needs to run on W2K, XP, 2003 and Vista. The application writes to HKLM in the registry and will only work on Vista if you run it as Administrator. My question is: can I force the app to run as Adminstrator automatically? Does it involve creating a manifest file? At the moment I...

Output conflicts between C & C++

Greetings Everyone I am currently trying to write a multi-language program (C, C++ and fortran) though am achieving segmentation errors. I've ruled out vectors and the like in: http://stackoverflow.com/questions/666320/accessing-public-class-memory-from-c-using-c I've narrowed now the cause to the use of 'cout' experssions in my C++ se...

#include <lib.h> gives symbol not found, why?

I have this code: #include <iostream> #include <mp4.h> int main (int argc, char * const argv[]) { // insert code here... std::cout << "Hello, World!\n"; MP4Read("filename", MP4_DETAILS_ALL ); return 0; } And i've added -I/opt/local/include and -L/opt/local/lib to the path (where the mp4 library resides after install...

fread error with DJGPP

While reading a binary file using DJGPP on DOS this code hangs. This happens when the fread call is made. If the call is removed then the program runs successfully. The same code runs fine through Visual C++ 2008. Has anyone experienced similar issues with djgpp ? Am I missing out on something really simple ? char x; string Filena...

C++: Cross thread exception handling problem with boost::exception

Basically, I've got a situation where one thread throws an exception which a different thread needs to handle. I'm trying to do this with boost exception, however somewhere along the line the exception loses its type and thus isn't caught by the catch blocks. Basically, thread B wants to do something, however for various reasons it mus...