How to get the invoked command and parameters as one string instead of a list of argv-s (especially gcc under Linux)?

Recommended Answers

All 3 Replies

Build it manually:

#include <iostream>
#include <string>

int main ( int argc, char *argv[] )
{
  std::string args;

  for ( int i = 0; i < argc; i++ ) {
    args += argv[i];

    if ( i != argc - 1 )
      args += ' ';
  }

  std::cout<< args <<'\n';
}

Yes, that's clear. I just thought there is a built-in function or environment variable.

>I just thought there is a built-in function or environment variable.
Built-in solutions usually arise from a very common problem or a difficult to implement problem. Yours is neither. You might get lucky, but more often than not you'll end up needing a third party or custom solution for uncommon and trivial to implement problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.