c++

Opening a document programatically in C++

I have a console program written in C++. Now I want to open a manual document(in .txt or .pdf) everytime a user of the program types 'manual' in console. How can I do this? Any links to a tutorial would be helpful.Thanks ...

C++ linker error

Hello: I have a file A.cpp which has the following lines: #include"B.h" int main(int argc, char **argv) { ... char *input_file = *argv; B *definition = new B(input_file); ... } In B.h, I have the following: class B { public: // Constructors B(void); B(const char *filename); ... } When I compile, I get the f...

Function pointers to member functions

There are several duplicates of this but nobody explains why I can use a member variable to store the pointer (in FOO) but when I try it with a local variable (in the commented portion of BAR), it's illegal. Could anybody explain this? #include <iostream> using namespace std; class FOO { public: int (FOO::*fptr)(int a, int b); int ad...

street light and shadow in opengl ?

To make a scene street illuminated, i tried, point source light, used glMaterial and used ambient light...... I get a scene fully illuminated, not exactly the way like street light, can anyone share resources or explain how exactly i can achieve this?? I went through many light resources in net, could not properly understand.... ...

C++ STL 101: Overload function causes build error

Trivial code that works if I do not overload myfunc. void myfunc(int i) { std::cout << "calling myfunc with arg " << i << std::endl; } void myfunc(std::string s) { std::cout << "calling myfunc with arg " << s << std::endl; } void testalgos() { std::vector<int> v; v.push_back(1); v.push_back(2); std::vector<std::...

C++: Pointers and scope

int* test( ) { int a = 5; int* b = &a; return b; } Will the result of test be a bad pointer? As far as I know a should be deleted and then b would become a messed up pointer, right? How about more complicated things, not an int pointer but the same with a class with 20 members or so? ...

Visualize the depth buffer

I'm attempting to visualize the depth buffer for debugging purposes, by drawing it on top of the actual rendering when a key is pressed. It's mostly working, but the resulting image appears to be zoomed in. (It's not just the original image, in an odd grayscale) Why is it not the same size as the color buffer? This is what I'm using the...

What's wrong with my recursive function?

So I'm trying to implement a recursive function that generates the entire game tree of Tic-Tac-Toe, and I can't seem to get it to work. void BuildTree(Node& nNode, const int& nextPlayer) { //Copy last board Ticboard tBoard = nNode.m_board; do { //Return first valid move int validMove = ...

How do I create "undo" in c++?

I've got a couple of codes to do some things but I need to create a function that undoes the previous task/addition/change.How do I do this in Borland C++? (the program stores strings of text in a text file using "list",it is stored and then erased unless I use the save-function I've created) right,so I don't know if I've forgotten to ...

Would this constructor be acceptable practice?

Let's assume I have a c++ class that have properly implemented a copy constructor and an overloaded = operator. By properly implemented I mean they are working and perform a deep copy: Class1::Class1(const Class1 &class1) { // Perform copy } Class1& Class1::operator=(const Class1 *class1) { // perform copy return *this; } Now l...

How to construct a c++ fstream from a POSIX file descriptor?

I'm basically looking for a C++ version of fdopen(). I did a bit of research on this and it is one of those things that seems like it should be easy, but turns out to be very complicated. Am I missing something in this belief (i.e. it really is easy)? If not, is there a good library out there somewhere to handle this? EDIT: here is a...

C++ reference type as instance variable in Objective-C++

C++ reference types as instance variables are forbidden in Objective-C++. How can I work around this? ...

Why the streams in C++?

As you all know there are libraries using streams such as iostream and fstream. My question is: Why streams? Why didn't they stick with functions similar to print, fgets and so on (for example)? They require their own operators << and >> but all they do could be implemented in simple functions like above, also the function printf("...

new vs2008 user

Hello, I am trying to build a release version of my project. Our prof made us create a static library which i built using debug version. then i made a release version of that static library using /mt as my c runtime now in my test application (release version) I use the same runtime option and add that static library and also ignore...

Which of FILE* or ifstream has better memory usage?

I need to read fixed number of bytes from files, whose sizes are around 50MB. To be more precise, read a frame from YUV 4:2:0 CIF/QCIF files (~25KB to ~100KB per frame). Not very huge number but I don't want whole file to be in the memory. I'm using C++, in such a case, which of FILE* or ifstream has better (less/minimal) memory usage? P...

Float to binary in C++

Hi, I'm wondering if there is a way to represent a float using a char in C++? For example: int main() { float test = 4.7567; char result = charRepresentation(test); return 0; } I read that probably using bitset I can do it but I'm not pretty sure. Let's suppose that my float variable is 01001010 01001010 010...

Show a download list with qt4

What is the best way to show a list of downloads using QT4? 1 QListWidget 2 QTreeWidget 3 QTableWidget Thanks ...

how to get data in the variable CURLOPT_FOLLOWLOCATION

how to get data in the variable CURLOPT_FOLLOWLOCATION? curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,1); ...

Video courses for learning C++

Do you have any recommendations on great video courses as a complement to books for learning C++? ...

how to handle delete by illegal address

Suppose we have a situation like this. Suppose instead of "p = " we called some function(written by someone which invalidate our pointer). How to handle this problem? How to protect code from crashes? I know about and use boost smart pointers. But what to do if we have this situation. struct Test { int a; int b; int c; }; T...