1

I am a macOS user and I am unfamiliar with windows powershell. I am required to write a c++ code for multiplication/addition of matrices. No big deal!

The instructor implied that the task will be executed by

./assignment1.exe C:/Users/delliott/mat1.txt C:/Users/delliott/mat2.txt

Do I have to hardcode the paths for my fstream? Or does it mean my code has to take the paths as an input? What approach is optimal so that my code’s getElement() reads the required file without failing?

vhmvd
  • 192
  • 3
  • 15
  • 1
    Good news: this works the same way on Windows as in MacOS or Linux. Do you know how to use the `argc` and `argv` parameters to `main()`? – Sam Varshavchik Feb 02 '20 at 14:36
  • @SamVarshavchik Unfortunately, I am not familiar with these parameters even though Xcode adds `int main(int argc, const char * argv[])` by default. – vhmvd Feb 02 '20 at 14:42
  • @drescherjm Yes! It at least gave me a hint. – vhmvd Feb 02 '20 at 14:44
  • 1
    In that case, your next step [would be a good C++ book which will explain them in detail](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Unfortunately, stackoverflow.com is not a replacement for a C++ book. It doesn't make much sense to copy/paste entire sections from a C++ book into here. But I'm wondering, how can your instructor expect you to use them, without having explaining the subject matter in class, first? I would think that before handing out an assignment that requires one to use command-line parameters, this will be explained in class, first. – Sam Varshavchik Feb 02 '20 at 14:44
  • @SamVarshavchik That’s neglecting on my end. However, I’ve got the idea. I just have to use `argv[]` for providing the paths. Correct? – vhmvd Feb 02 '20 at 14:48
  • 1
    That is correct. And argc to know how many arguments are passed. Look at the examples in the linked duplicate because argv[0] will not be the first argument that you pass. – drescherjm Feb 02 '20 at 14:50
  • 1
    Now, you have to use both `argc` and `argv` in order to it correctly and intelligently handle the wrong number of command line parameters. I'm almost certain that unless your program implements error handling correctly, its grade will be penalized; and only a C++ book will give you complete details. C++ is the most complicated general purpose programming language in use today. You can't expect to skip out on important material, and expect to make it up by asking strangers on the Internet, for help. – Sam Varshavchik Feb 02 '20 at 14:51

0 Answers0