Hi,
I am using copy_n from GNU C++ Library under Ubuntu 8.10. My code is like this:

#include <ext/algorithm>
using namespace std;

void myfun(char * flags ) {
    char * flags_new = new char[3];
    copy_n(flags, 3, flags_new);// both copy_n and copy would give not in this scope error.
    delete [] flags_new;
  }

int main()
{
    char flags[3]={'a','b','c'};
    myfun(flags );
    return 0;
}

I got error : "‘copy_n’ was not declared in this scope".
I look up for copy_n in GNU C++ standard library document and find "ext/algorithm" to include. I was wondring what is the problem and how to fix it? Thanks!

The GNU implementation of copy_n is in the __gnu_cxx namespace. Try putting using __gnu_cxx::copy_n after your #include and your program should compile fine.

Be a part of the DaniWeb community

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