Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

4. Name and describe the main internal sources of candidates.

Answered: 1 week ago

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago