0

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!

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by John A
1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.