EDIT: I mucked up the thread title. It should be "Convert Custom type 'String' to std::string"
Hi,
How would I be able to convert a custom type 'String' to a std::string? Just that the function I'm using requires a std::string.
troublesome code:
SetVar::operator char* ()
{
if (szName == "Passwd")//only create a md5 hash for the password, not anything else
{
std::string pwd;
//here i need to convert 'sVal' from a String to a std::string called 'pwd'
return md5.getHashFromString(pwd);
}
return sVal;
}
types.cpp
// types.cpp
//
#include "types.h"
//
// String
//
String::String()
{
szStr = NULL;
}
String::String(char *str)
{
*this = str;
}
String::~String()
{
if (szStr) {
free(szStr);
szStr = NULL;
}
}
String& String::operator= (char *str)
{
if (szStr) {
free(szStr);
szStr = NULL;
}
if (str)
szStr = strdup(str);
return *this;
}
String::operator char* ()
{
return szStr;
}
bool String::operator== (char *str)
{
if (!strcmp(szStr, str))
return true;
else
return false;
}
types.h
// types.h
//
#ifndef TTYPES_H
#define TTYPES_H
#include <windows.h>
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
#define WSTD_DEL(x) { if ((x)) { delete (x); (x)=NULL; } }
#define WSTD_DELM(x) { if ((x)) { delete[] (x); (x)=NULL; } }
//
// String
//
class String
{
public:
String();
String(char *str);
~String();
String& operator= (char *str);
operator char* ();
bool operator== (char *str);
private:
char *szStr;
};
#endif
Thanks in advance.
vs49688