• Advertisement

Archived

This topic is now archived and is closed to further replies.

Problem with loging function

This topic is 5289 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! In my login class i have this function:
	// ==================================

	void CLog::Message(std::string Message, ...)
	{
		Guard(CLog::Message);

		// Compile string to output

		va_list argList;
		va_start(argList, Message);

		m_LogStream << Message << argList << std::endl;

		va_end(argList);

		if (m_ForeFlush) m_LogStream.flush();

		Unguard();
	}
Now i want to do something like this: gLog->Message("Soundcard has %d hardware channels", m_HardwareChannels); And it returns this: Soundcard has %d hardware channels Hmm... where could be the error? Thanks, Christian

Share this post


Link to post
Share on other sites
Advertisement
Streams don''t expand the % specifiers. The idea is you use << to remove the need for them. If you want to use the C style then use vfprintf (or similar).

Share this post


Link to post
Share on other sites
Hmmm...

I am now using my String class (bases on std::string) and has the << operator.

gLog->Message(String("Soundcard has ") << m_HardwareChannels <<" hardware channels");

Is there a better way?

Something like

gLog->Message("Soundcard has " << m_HardwareChannels <<" hardware channels");

would be very cool.

Thanks, Christian

Share this post


Link to post
Share on other sites
A possibility:

std::ostream& CLog::Message() { return m_LogStream; }

...

gLog->Message() << "Soundcard has " << m_HardwareChannels << " hardware channels";

Share this post


Link to post
Share on other sites
try this:


void Info (const char* lFmtCtrlStr,...);
void Info (const std::string& lString);

// so u can do this

glog.Info("text");
// or this

glog.Info("text = %s",text);


Share this post


Link to post
Share on other sites

  • Advertisement