Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created?
How does the comparison parameter in next_permutation() work?
Is it possible to use std::next_permutation() to permutate the elements of a vector of a class i created?
Yes!
Try this
#include<iostream>
#include<vector>
#include<algorithm>
int main()
{
typedef std::vector<int> V; //<or_any_class>
V v;
for(int
I'm a Java programmer, but now I have to write a little bit of code in c++. I learned the basics of C++ a couple of years ago, so I'm not really fit.
I wrote a little class which describes a Polynomial. Here it is:
#include "Polynom.h"
#include <iostream>
using namespace std;
Polynom::Polynom()
{
this->degree = 0;
this->coeff = new int[0];
}
Polynom::Polynom(int degree)
{
this->degree = degree;
this->coeff = new int[degree +
The question whether a multimap preserves the insertion order of identical keys has been asked numerous times and I think it is pretty clear that the standard says it doesn't. Although apparently C++0x for a while said it did and then didn't again?
Anyway, I need a structure on which I can look up by key, and iterate over it in insertion order for identical keys. Which means I can't use compound keys, as then how could I look up by key?
So, does VC++ maintain the insertion order of
Given a structure such as below
class A {
int test;
void f() { int test; }
}
I just had a curious case in which the code in f(), when referring to test, compiled under VS2010, correctly referred to the function local variable, however, when compiled under gcc, incorrectly referred to the member variable. Took me quite a while to track down.
Anyway, question is, is there an option in gcc or VS to enable compiler warnings every time a member variable is re-declared in a local
How to get current date d/m/y. I need that they have 3 different variables not one, for example day=d; month=m; year=y;.
For linux, you would use the 'localtime' function.
#include <time.h>
struct tm *aTime = localtime(time(NULL));
int day = aTime->tm_mday;
int month = aTime->tm_mon + 1; // Month is 0 - 11, add 1 to get a jan-dec 1-12 concept
int year = aTime->tm_year + 1900; // Year is # years since 1900
The ctime library provide such functionnality.
Also
I have a c++ and a c# project in Visual Studio 2008. The c++ project uses an API that was built in VS2005. I need that c++ project to reference the standard library files from VS2005. The order that the compiler searches the include directories keeps pointing to the include files from VS2008, specifically the vector file. It crashes the program when running in Release when it references the vector file from VS2008. How do I force the c++ project to use the include directories from
I wanted to use DevC++ on Linux, so I've started it with wine and everything is OK until it came to run the file.
The C file compiles well and a .exe files generated that is able to run on Linux (without wine)
$ file '/media/F6AC746BAC74286F/Dev-Cpp/work/hello_on_nix.exe'
/media/F6AC746BAC74286F/Dev-Cpp/work/hello_on_nix.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit
$ '/media/F6AC746BAC74286F/Dev-Cpp/work/hello_on_nix.exe'
Hello World!
But the problem is when I
I've not done much coding for Windows lately, and I find myself sitting at Visual Studio right now, making a small program for Windows 7 in C++. I need some configuration data to be read/written.
In the old days, (being a Borland kind of guy) I'd just use a TIniFile and keep the .ini beside my exe Obviously this is just not the done thing any more. The MS docs tell me that Get/WritePrivateProfileString are for compatibility only, and I doubt that I'd get away with writing to
I am having trouble understanding the difference between Array obj; and Array* obj = new Array; while overloading the array index operator []. When I have a pointer to the object, I get these error messages on VS 2010.
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
could be 'Array &Array::operator =(const Array &)' while trying to match the argument list '(Array, int)'
#include
I'm trying to specialize the member function moment() only (not the hole class) like this:
template<class Derived, class T>
class AbstractWavelet {
public:
[...]
template<bool useCache>
const typename T::scalar moment(const int i, const int j) const {
return abstractWaveletSpecialization<Derived, T, useCache>::moment(static_cast<const Derived*>(this), i, j);
}
template<bool useCache>
friend const typename T::scalar
Hey, id like to make this as fast as possible because it gets called A LOT in a program i'm writing, so is there any faster way to initialize a C++ vector to random values than:
double range;//set to the range of a particular function i want to evaluate.
std::vector<double> x(30, 0.0);
for (int i=0;i<x.size();i++) {
x.at(i) = (rand()/(double)RAND_MAX)*range;
}
EDIT:Fixed x's initializer.
Right now, this should be really fast since the loop won't
I have a class State that has a string data type called moveType. In the implementation of my code, I am calling a setter void setMoveType(string _moveType); and it's implemented with just moveType = _moveType;
When I call my getter string getMoveType() const; on an instance of State and output it to cout, nothing is displayed.
I am couting upon entering the getMoveType() function. The parameter indeed has the correct value, but it appears that it's not getting set at all.
Does