I have the line

#include <algorithm>

at the top of a file, and the line


in one of the fuctions in that file. However, when I try to compile it I get the error
error C3861: 'nth_element': identifier not found
at that line. I would expect this if I hadn't included <algorithm> but I did include it. So why am I getting it?

Did you prefix the name with the namespace?

std::nth_element(minRollArray, minRollArray+n, minRollArray+numSets);

Probably because you didn't specify the namespace. nth_element is an std function so is only defined in the std namespace.

U have some options:
- Use std::nth_element
- Put using std::nth_element; after including the header file
- Put using namespace std; after including the header file (not a very sexy solution).

// vc3.cpp : main project file.

#include "stdafx.h"
int main()
    int a=10,b=20;
   int swapr(&a,&b);
    printf("a=%d and b=%d",a,b);

   int swapr(int *x,int *y)
    int t;


i'm getting error here how to solve it...i'm new in this field,i m using vc++..thanku

i m getting error here how to solve it...i m new in this field,i m using vc++..thanku

Not sure why you posted it in this thread instead of creating a new one, but I'm happy to answer anyway

a few things:

  1. You need to declare the function swapr before it is used. You can do this by adding a function prototype above the main function (or, alternatively, by just putting the entire function definition up there, instead of below it).
  2. In main, when you call swapr, you simply use the name of the function, you don't need the return type as well.
  3. You don't have any return statement in the swapr function.
  4. The return type of swapr should be void, not int.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.