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 6601885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:48:39+00:00 2026-05-25T18:48:39+00:00

I have a bunch of .cpp files which together process similar data files but

  • 0

I have a bunch of .cpp files which together process similar data files but of various sizes. For the larger data files I want to do some timing studies on the functions inside the .cpp files.

I would like to suppress the output the results for these big data sets, and only print the timing results. For smaller data sets, I would like to print to the screen to verify algorithm/code correctness.

Rather than repeatedly commenting/uncommenting out the appropriate cout statements and recompiling , I would like to use command line arguments (or some other technique) to selectively suppress output.

Any suggestions? The naive one I can think of is use argc and argv, but I am not sure if they are global variables which can be used by functions across different files.

  • 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-25T18:48:40+00:00Added an answer on May 25, 2026 at 6:48 pm

    Your intuition is correct — use the argc and argv values passed into your main function — but they are not global variables. You need to make your information global somehow: I’d recommend parsing the arguments once, and keeping a set of global flags that can easily be queried.

    For example:

    // In a common header file that gets included in each source file
    extern bool g_bFlag1;
    extern bool g_bFlag2;
    ...
    
    // In your main source file
    bool g_bFlag1 = false;
    bool g_bFlag2 = false;
    ...
    int main(int argc, char **argv)
    {
        // Parse command line and store results in global flags
        for (int i = 1; i < argc; i++)
        {
            if (strcmp(argv[i], "--flag1") == 0)
                g_bFlag1 = true;
            else if (strcmp(argv[i], "--flag2") == 0)
                g_bFlag2 = true;
            else
                ;  // etc.
        }
    }
    
    // In any other source file:
    if (g_bFlag1)
    {
        // do stuff if and only if g_bFlag1 is set
    }
    

    Then you can pass --flag1 on the command line. For more complicated argument parsing, I’d suggest using a library such as GNU getopt.

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

Sidebar

Related Questions

I have a bunch of classes I want to rename. Some of them have
I have a bunch of files in different folders: /ai/client.cpp # contains the main
I have source in a bunch of subdirectories like: src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp In
We have bunch of Domain Entities which should be rendered to an html format,
I have a bunch of files that I need to be able to transport
I have a bunch of perfmon files that have captured information over a period
I have a bunch (hundreds) of files that are supposed to have Unix line
i have bunch of log files and I have to delete the files of
I have bunch of files and very file has a header of 5 lines.
I have bunch of methods in which i need to test whether remote server

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.