The stripped version of my IString class:
Code:
///////////////////////////////////////////////////////////////////////
// istring.hpp
///////////////////////////////////////////////////////////////////////
#include <string>
#include <istream>
using namespace std;
class IString
{
private:
string buffer;
public:
IString();
IString (char* str);
IString(const char* pChar);
operator char* ( ) const;
};
///////////////////////////////////////////////////////////////////////
// istring.cpp
///////////////////////////////////////////////////////////////////////
#include <istring.hpp>
IString::IString()
{
}
IString::IString(char * str)
{
buffer = str;
}
IString::IString(const char* pChar)
{
buffer = pChar;
}
IString:
{
return (char *) buffer.data();
}
This is the code that calls it:
Code:
#include <iostream>
#include <fstream>
#include <istring.hpp>
using namespace std;
using std::ifstream;
int main()
{
char dbszSQL[1024];
IString theStartDate("2004-01-01-00.00.00.000000"), theEndDate("2005-01-01-00.00.00.000000");
sprintf(dbszSQL, " hello IString %s AND %s ", theStartDate, theEndDate);
cout<< dbszSQL<< endl;
cout<<theStartDate<<endl;
cout<<theEndDate<<endl;
return(0);
}
This is the output I get:
hello IString D AND 2004-01-01-00.00.00.000000
This is the output I expect:
hello IString 2004-01-01-00.00.00.000000 AND 2005-01-01-00.00.00.000000
What am I missing? I know this is possible and I don't want to cast the object or call a method that returns a char*. Your help would be greatly appreciated.