Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5960143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:47:06+00:00 2026-05-22T18:47:06+00:00

I am developing a GUI app on WinXP but unfortunately std::cerr/cout goes nowhere. I

  • 0

I am developing a GUI app on WinXP but unfortunately std::cerr/cout goes nowhere. I would like to add a simple debug method that appends messages to a log file.

I have been hashing together an almost workable solution reading other posts. And am able to have a single debug() method call in my GUI app. However, don’t even get that far in the below example app I am trying to use to find a solution.

Using:

  • Dev-C++ v4.9.9.2
  • WinXP

Below is the structure of my example app:

C:.
|   Makefile.win
|   Project1.dev
|
\---src
    |   bar.cpp
    |   bar.h
    |   foo.cpp
    |   foo.h
    |   main.cpp
    |
    +---inc
    |       debug.h
    |
    \---log

src/bar.h:

#ifndef BAR_H
#define BAR_H

class Bar
{
public:
    Bar();  
};
#endif

src/bar.cpp:

#include "bar.h"

Bar::Bar()
{
//    debug("I am Bar.");
}

src/foo.h and src/foo.cpp are the same except change ‘Bar’ to ‘Foo’

Using information that I have found in other articles…

src/inc/debug.h:

#ifndef MY_DEBUG_H
#define MY_DEBUG_H

#include <iostream>
#include <fstream>
#include <string>

#ifndef LOGFILE
#define LOGFILE std::ofstream logfile("log/debug.txt", std::ios::app);
#endif

#ifndef debug
#define debug(s) LOGFILE << "[" << __DATE__ << " " << __TIME__ \
            << "] " << __FILE__ << ":" << __LINE__ << " " << s << std::endl

#endif

#endif

src/main.cpp:

#include "inc/debug.h"
#include "foo.h"
#include "bar.h"

#include <iostream>

int main (int argc, char **argv)
{
    debug("Starting program."); 
    Foo *f = new Foo();
    Bar *b = new Bar();
}

When I attempt to compile this I get an error at the debug("Starting program."); line in main.cpp saying expected primary-expression before '<<' token.

Could someone tell me what causes this error and also a good way to then be able to apply debug messages in other files/classes i.e. uncomment the lines:

//    debug("I am Bar.");
//    debug("I am Foo.");

in bar.cpp and foo.cpp respectively and use debug() anywhere else?

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:47:07+00:00Added an answer on May 22, 2026 at 6:47 pm

    Your define for logfile is messed up.

    When your code is preprocessed you’ll get:

    std::ofstream logfile("log/debug.txt", std::ios::app); << "[" << __DATE__ << " " << __TIME__ \
            << "] " << __FILE__ << ":" << __LINE__ << " " << "Starting Program" << std::endl;
    

    What you would need to do is something like this in a header file:

    extern std::ofstream LOG_FILE;
    

    and in some cpp file (perhaps your main.cpp file):

    #include "debug.h"
    std::ofstream LOG_FILE("log/debug.txt",std::ios::app);
    

    To disable debugging you could do something like:

    #define debug(ignore)((void) 0)
    

    When your debug flag isn’t enabled compared to your other debug definition.

    You could also put the class initialization in a similar #ifdef block to avoid opening the file when you aren’t using it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a GUI app in C#. It's a multithread app, and I would
Is NetBeans recommended for developing a GUI for a Python app? Does it have
I've been developing a GUI library for Windows (as a personal side project, no
I am developing a c# GUI and was wondering if there were any (preferably
Developing websites are time-consuming. To improve productivity, I would code a prototype to show
I am developing a GUI application in Qt Creator and want to write some
XulRunner/Gecko seems to be really interesting for developing GUI-intensive applications (by using widely used
I am developing a GUI that has a canvas and a bunch of controls
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.