Question
I am having trouble with a simple C++ program: Here is what I have coded thus far: I have error messages that read: In function
I am having trouble with a simple C++ program:
Here is what I have coded thus far:
I have error messages that read:
In function int main():
error: invalid initialization of reference of type std::ifstream& {aka std::basic_ifstream
note: in passing argument 1 of int myLineCounter(std::ifstream&) int myLineCounter(ifstream& myFile); ^~~~~~~~~~~~~
In function int myLineCounter(std::ifstream&):
error: declaration of std::ifstream myFile shadows a parameter ifstream myFile("sample.txt"); ^ Any help would be appreciated.
Create a sample text called sample.txt, with multiple lines and spaces between these ines Open and read the file using file operations. Create a function called myLineCounter and count the number of lines in the file, also print the value that you get. 1. 2. 3. myLineCounter(ifstream& myFile) For example, if my sample text looks like this: The Project Gutenberg EBook of The Adventures of Sherlock Holmes by Sir Arthur Conan The Project Gutenberg EBook of The Adventures of Sherlock Holmes by Slir Arthur Conan Doyle (#15 in our series by Sir Arthur Conan Doyle) Copyright laws are changing all over the world. Be sure to check the copyright laws for your country before downloading or redistributing this or any other Project Gutenberg eBook. Your output should be: This file has 4 lines
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