c++

Linked list Recursion ...

hey , I'd like to make a recursive function using C++ I make this class class linklist { private: struct node { int data; node *link; }*p; }; void linklist::print_num(node* p) { if (p != NULL) { cout << p->data << " "; print_num (p->link); } } in the main program what should I write ... ...

Simple vector program error

Hi iam new to c++ and iam trying out this vector program and i am getting the following error: error: conversion from test*' to non-scalar typetest' requested| Here is the code #include <iostream> #include <fstream> #include <vector> #include <string> using namespace std; class test{ string s; vector <string> v; public: ...

How can I fix my program from crashing in C++?

I'm very new to programming and I am trying to write a program that adds and subtracts polynomials. My program sometimes works, but most of the time, it randomly crashes and I have no idea why. It's very buggy and has other problems I'm trying to fix, but I am unable to really get any further coding done since it crashes. I'm completely ...

defining < operator for map of list iterators

I'd like to use iterators from an STL list as keys in a map. For example: using namespace std; list<int> l; map<list<int>::const_iterator, int> t; int main(int argv, char * argc) { l.push_back(1); t[l.begin()] = 5; } However, list iterators do not have a comparison operator defined (in contrast to random acc...

Questions on usages of sizeof

Question 1 I have a struct like, struct foo { int a; char c; }; When I say sizeof(foo), I am getting 8 on my machine. As per my understanding, 4 bytes for int, 1 byte for char and 3 bytes for padding. Is that correct? Given a struct like the above, how will I find out how many bytes will be added as padding? Question 2 I am...

AESlibrary only two lines

Does anyone know a c++ library that uses advanced encryption standard encryption that can achieve encryption and decryption (using counter mode) in just two lines of codes. No need of padding or buffering the plaintexts the library will take care of all this. I have had a look at crypto++, openssl and libtomcrypt but in these it seems I ...

variable size datatype(int) in c++

Hello I want to use a datatype to represent sizes like 3bits or 12bits.. can anyone tell me how can I implement this in c++ and is there any code like this, which can help me define size in bits int i:3; thanks in advance .. ...

How to optimize erasing from multimap

I have two multimaps defined so multimap phoneNums; and multimap numPhones; they are some kind of phone registry - phoneNums contains Key name, and second argument phonenumber, numPhones contain Key phonenumber and second is name. I want to optimize erase from both of them when i want to delete string Key form phoneNums, which is also se...

Compiler optimization of references

I often use references to simplify the appearance of code: vec3f& vertex = _vertices[index]; // Calculate the vertex position vertex[0] = startx + col * colWidth; vertex[1] = starty + row * rowWidth; vertex[2] = 0.0f; Will compilers recognize and optimize this so it is essentially the following? _vertices[index][0] = startx + col * ...

error: initializer fails to determine size of ‘K’

I get the error "intitializer fails to determine size of 'K'"at line int K[]= new int[Vertices->total]; How do I solve it? ...

Folder copy VC++

i want to copy a directory from one drive to another drive. My selected directory contain many sub directories and files. How can i implement the same using vc++ ...

invalid cast from type ‘CvSeq’ to type ‘CvPoint* (How to typecast in Opencv)

i get the error at line below Vertex2 = (CvPoint*)Vertices[I]; //where vertices is cvseq of contour and Vertex2 is cvpoint i get error invalid cast from type ‘CvSeq’ to type ‘CvPoint* how do i solve this ...

Generation of an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level

I'd like to generate an array of Random numbers with defined Min, Max, Mean and Stdev with given number of elements and error level. Is there such a library in C, C++, PHP or Python to do so? Please kindly advise. Thanks! ...

Changing code at runtime

I have a pointer to a function (which i get from a vtable) and I want to edit the function by changing the assembler code (changing a few bytes) at runtime. I tried using memset and also tried assigning the new value directly (something like mPtr[0] = X, mPtr[1] = Y etc.) but I keep getting segmentation fault. How can I change the code?...

cvHaarDetectObjects(): "Stack aound the variable 'seq_thread' was corrupted."

I have been looking in to writing my own implementation of Haar Cascaded face detection for some time now, and have begun with diving in to the OpenCV 2.0 implementation. Right out of the box, running in debug mode, Visual Studio breaks on cvhaar.cpp:1518, informing me: Run-Time Check Failure #2 - Stack aound the variable seq_thread...

is back_insert_iterator<> safe to be passed by value?

I have a code that looks something like: struct Data { int value; }; class A { public: typedef std::deque<boost::shared_ptr<Data> > TList; std::back_insert_iterator<TList> GetInserter() { return std::back_inserter(m_List); } private: TList m_List; }; class AA { boost::scoped_ptr<A> m_a; public: AA()...

Windows Programming in C++

Being a C#/Java programmer, I really need to know a fact: Has Windows Programming with Win32SDK/MFC/wxWidget become antiquated? What is the status of popularity of these technologies in software industry now? Being a C#/Java programmer, do I need to learn Win32SDK/MFC/wxWidget now? ...

How can I write a function template for all types with a particular type trait?

Consider the following example: struct Scanner { template <typename T> T get(); }; template <> string Scanner::get() { return string("string"); } template <> int Scanner::get() { return 10; } int main() { Scanner scanner; string s = scanner.get<string>(); int i = scanner.get<int>(); } The Scanner class i...

dynamic linking:change of the linking path.

Normally it happens that when ever the path of the library that has to be linked dynamically is defined in LD_LIBRARY_PATH or it it will be mentioned with -L flag while creating the binary. In actual scenario if ,lets say the binary has been built and deployed at the client place. Now if there is a change in the path of one of the dyn...

What is the modern equivalent (C++) style for the older (C-like) fscanf method?

What is the best option if I want to "upgrade" old C-code to newer C++ when reading a file with a semicolon delimiter: /* reading in from file C-like: */ fscanf(tFile, "%d", &mypost.nr); /*delimiter ; */ fscanf(tFile, " ;%[^;];", mypost.aftername);/* delimiter ; */ fscanf(tFile, " %[^;]", mypost.forename); /*delimiter ; */ fscanf(tFil...