-5

I have a section of downloaded source code, when trying to compile via Cygwin using g++ compiler, the compiler gives me an error saying that the 'transform' function is undeclared in this scope...

I am using the std namespace, and I have the correct headers. I am not sure why it is not compiling.. The syntax looks correct

Here is the code block section.

string tolower (const string & s)
  {
    string d = s;
    transform(d.begin(), d.end(), d.begin(), (int(*)(int)) tolower);
    return d;
  }  // end of tolower

Here is my header section:

#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>

// standard library includes ...

#include <string>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stdexcept>
#include <fstream>
#include <iostream>
#include <sstream>
#include <ios>
#include <iterator>

using namespace std; 
Uys of Spades
  • 173
  • 1
  • 9

1 Answers1

5

You need to include the appropriate header for std::transform:

#include <algorithm>

You should also avoid using namespace std; in the global namespace in headers, you pollute the global namespace of any code that includes your header file.

See this post about using namespace std.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480