Hello, there. I am trying to open a txt file. There are many text files that I will be opening in the code that is why I am trying to create a function where you can print the string inside the txt file but I am having an error. What can I do to solve this problem? Thank you.
Your lines 5 through 18 aren't part of a function, so that appears to be the most glaring issue.
Second issue is that you have a semi-colon on line 36, making your loop an infinite loop:
1 2 3 4
while (condition);
{
statements;
}
means
1 2 3 4 5 6 7 8
while (condition)
{
// nothing
}
{
statements;
}
ofstream = OUTPUT stream. You write to an output stream.
ifstream = INPUT stream. You read from an input stream.
If you're trying to open an existing file, you want an input stream.
Hope that helps.