I have this function that I tested outside the current solution and it worked fine. When I moved it into the new solution and changed it to search data which is an unsigned char. The function stopped returning the correct value. Also believe it or not I was getting four seperate correct answers on the returns!
[code]#include <string>
#include <iostream>
int Count( const std::string & str,
const std::string & obj ) {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
std::string ::size_type pos = 0;
while( (pos = obj.find( str, pos ))
!= std::string::npos ) {
a++;
b++;
c++;
d++;
pos += str.size();
}
return a;
return b;
return c;
return d;
}
void printTcpContent(unsigned char *data,int)
{
std::string s = (const char*) data;
int a = Count( "text/html", s );
int b = Count( "text/plain", s );
int c = Count( "image/jpg", s );
int d = Count( "image/png", s );
std::cout << a << std::endl;
std::cout << b << std::endl;
std::cout << c << std::endl;
std::cout << d << std::endl;
}
For whatever reason it works. Now for the problem at hand......
void printTcpContent(unsigned char *data,int)
{
std::string s = (const char*) data;
This is the problem. data is an unsigned char and std::string doesn't reconize it. What to do?
Back on topic, could you give us the exact error that the compiler gives you?
Also std::string s = (char*) data; should work fine.
Although you should use the more C++-like std::string s = reinterpret_cast<char *> (data); instead.