Hello, C++ experts,
I am writing a Log class something like below.
================= c++ source code ========================
class Log {
public:
Log();
Log(string _filename);
~Log();
public:
template<typename paramT>
void operator<<(const paramT& param)
{
ofstream outfile;
char argument[256] = {0};
sprintf (argument, "%s", filename.c_str());
outfile.open(argument, ios::app);
outfile << param;
};
private:
string filename;
};
================= c++ source code ========================
and I use above like
================= c++ source code ========================
Log log("Process.txt");
vector<Edge*>::iterator ei;
for ( ei = edgeSet.begin(); ei != edgeSet.end(); ++ei )
{
log << (*ei)->GetEdgeID(); // => works, for sure...
log << "Edge ID: " << (*ei)->GetEdgeID() << " "; // => fails..
}
================= c++ source code ========================
As you may see, ( log << (*ei)->GetEdgeID(); ) works fine,
but, ( log << "Edge ID: " << (*ei)->GetEdgeID() << " "; ) just fails...
clearly because the operator must deal with more than one different output
types like string, integer, and many other data types...
What can be the best measures for this?