Question
I want to input a txt file through argv[1] in c++, however, I can't find a way to let the program successfully read the file
I want to input a txt file through argv[1] in c++, however, I can't find a way to let the program successfully read the file I want, in fact, it didn't even read anything.
Can someone tell me how to let the program read the file? Do I execute it through the terminal? (I am using macOS), if yes then what should be the code for the terminal to run the program and read the right file. Please let me know if there is another way around. Thank you!
Here is my code
std::ifstream inFile(argv[1]);
if(!inFile.is_open()){
exit(EXIT_FAILURE);
}
inFile >> numRows >> numCols >> minVal >> maxVal;
inFile.close();
std::cout << numRows << std::endl;
std::cout << numCols << std::endl;
std::cout << minVal << std::endl;
std::cout << maxVal << std::endl;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started