Q:

Write a main function that takes two arguments. Concatenate the supplied arguments and print the resulting string

0

Write a main function that takes two arguments. Concatenate the supplied arguments and print the resulting string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <string>

int main(int argc, char *argv[]) {
  std::cout << "All " << argc << " argument"
            << (argc > 1 ? "s are:" : " is:") << std::endl;
  for (int i = 0; i < argc; ++i)
    std::cout << i << "\t" << argv[i] << std::endl;
  if (argc < 3)  // programname argument1 argument2 0
    return -1;
  std::string args(argv[1]);
  args += argv[2];
  std::cout << args << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now