c++

Initializing a vector with stream iterators

I'm trying to initialize a vector using iterators and I'm getting a compiler error basically saying that there's no matching function to call. The code reads from a file with an istream_iterator and ends with an input sentinel. Then I try to initialize the vector with those two iterators. #include "std_lib_facilities.h" #include<itera...

Way to determine proper predicate for templated types

Suppose I have a function which looks like this: template <class In, class In2> void func(In first, In last, In2 first2); I would like this function to call another function which accepts a predicate. My initial instinct was to do something like this: template <class In, class In2> void func(In first, In last, In2 first2) { typed...

Finding the Difference between the contents in two Files

I am developing a Application which takes two Files and output will be two files which will have only the contents which differs in both the files. The application is developed using VC++ My Files are of Html type Is there any library which will do the diff opereation between two files ...

How to expand an array dynamically in C++? {like in vector }

Lets say, i have int *p; p = new int[5]; for(int i=0;i<5;i++) *(p+i)=i; Now I want to add a 6th element to the array. How do I do it? ...

variable parameter function, how to make it type safe and more meaningful?

I am a newer for C++, and my first language is Chinese, so my words with English may be unmeaningful, say sorry first. I know there is a way to write a function with variable parameters which number or type maybe different each calling, we can use the macros of va_list,va_start and va_end. But as everyone know, it is the C style. When we...

C++ for Web Development

Regardless of how hard/long it is, has anybody ever used C or C++ for web development? ...

C++, Free-Store vs Heap

Dynamic allocations with new/delete are said to take place on the free-store,while malloc/free operations use the heap. I'd like to know if there is an actual difference, in practice. Do compilers make a distinction between the two terms? (Free store and Heap, not new/malloc) ...

accepting a grammar in C++

this is a lab assignment i am stuck on. i cant believe i am having problems with this basic programming, but i cant afford to waste any more time on this. i gotta ask the experts. i need to accept this grammar (ab)*b, which basically means any number of "ab" and ending with b. i have written this code but somehow, it checks only the fi...

Is it safe to read an integer variable that's being concurrently modified without locking?

Suppose that I have an integer variable in a class, and this variable may be concurrently modified by other threads. Writes are protected by a mutex. Do I need to protect reads too? I've heard that there are some hardware architectures on which, if one thread modifies a variable, and another thread reads it, then the read result will be ...

Problem with Macros

HI , Can some one help me in understanding why the value of SQUARE(x) is 49 ? I am using Visual C++ 6.0 . #define SQUARE(X) X * X int main(int argc, char* argv[]) { int y = 5; printf("%d\n",SQUARE(++y)); return 0; } ...

Calculating 3D tangent space

In order to use normal mapping in GLSL shaders, you need to know the normal, tangent and bitangent vectors of each vertex. RenderMonkey makes this easy by providing it's own predefined variables (rm_tangent and rm_binormal) for this. I am trying to add this functionality to my own 3d engine. Apparently it is possible to calculate the tan...

How can I create a static object member of class?

Hi people, I am fairly new to c++, especially in its techniques. My question is, how can I create a static object member of a class itself. What I mean is I declared a static member object inside a class. Example: CFoo:CFoo *pFoo[2] = {0}; class CFoo { public: static CFoo *pFoo[2]; public: CFoo(int a); public: CFoo *getFoo();...

QThread::wait() and QThread::finished()

Does QThread::wait() return (i.e., unblocks execution) after calling all the slots that were associated with QThread::finished() signal? Thanks in advance. ...

FFT Problem (Returns random results)

Hello, I've got this code, but it keeps returning random frequencies from 0 to about 1050. Please can you help me understand why this is happening. My data length is 1024, sample rate is 8192, and data is a short array filled with input data from the mic. float *iSignal = new float[2048]; float *oSignal = new float[2048]; int pitch =...

Adding VC++ to Eclipse toolchain

I want to write a program to link with binaries already created with VC++. What are the steps to add a toolchain for VC++ in Eclipse? Has anyone tried it successfully? If so, does the debugger still work? ...

Simple C++ code (what's wrong here?)

Noob to C++. I'm trying to get user input (Last Name, First Name Middle Name), change part of it (Middle Name to Middle Initial) and then rearrange it (First Middle Initial Last). Where am I messing up in my code? --Thanks for ANY help you can offer! ... #include <iostream> using std::cout; using std::cin; #include <string> using...

typechecking provided on enum

I would expect the following code snippet to complain about trying to assign something other that 0,1,2 to a Color variable. But the following does compile and I get the output Printing:3 3 Can anybody explain why? Is enum not meant to be a true user-defined type? Thanks. enum Color { blue=0,green=1,yellow=2}; void print_color(Colo...

QCalendarWidget as "Pop-up", not as new Window?

Hi there. I want to create a Settings-Widget, where I can choose a Date. Because it isn't nice to create 3 QLineEdits to call the QDate-Constructor with QDate(int year, int month, int day), I thought it would be better, if you can push a "show calendar"-Button for example, where you can choose the date. But I don't want to show this cal...

C Static Array Initialization - how verbose do I need to be?

To initialize an int array with all zeros, do I need to use: int foo[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; Or, will this work: int foo[10] = {0}; ...

Protect private key in Qt application

I have a Qt application written in C++ that uses a SSL-connection (QSslSocket) with another application for extra security. However, the application has a private key embedded in it. With applications like Process Explorer it's really easy to fish out the private key. (Properties of file -> Strings) Security is not very important for m...