I am trying to make a program that opens a file and hunts for some values in the file. I'm doing this by making a function that is given a reference keyword and the file as inputs, and calling it within the main function and I'm finding errors saying that some functions have been deleted.
My Code
#include<iostream>
#include<fstream>
using namespace std;
string findLine( ifstream openFile, string reference){
string line;
getline(openFile,line);
while(line.find(reference) == std::string::npos){
getline(openFile,line);
}
return line;
}
int main()
{
ifstream file;
string name;
cin >> name;
file.open(name); //opens file
if(!file.is_open()){"error while opening the file";
}else{
string ref;
ref = "TOGW";
string TOGW;
TOGW = findLine(file, ref);
}
}
The errors:
[{
"resource": "/c:/Users/zhtho/OneDrive/Documents/Research/C++ Programming/Programs/Research/newProcessor.cpp",
"owner": "cpptools",
"severity": 8,
"message": "use of deleted function 'std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const std::basic_ifstream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]'",
"source": "gcc",
"startLineNumber": 29,
"startColumn": 24,
"endLineNumber": 29,
"endColumn": 24
}]
and
[{
"resource": "/c:/Users/zhtho/OneDrive/Documents/Research/C++ Programming/Programs/Research/newProcessor.cpp",
"owner": "C/C++",
"code": "1776",
"severity": 8,
"message": "function \"std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const std::basic_ifstream<_CharT, _Traits> &) [with _CharT=char, _Traits=std::char_traits<char>]\" (declared at line 590 of \"C:\\msys64\\mingw64\\include\\c++\\12.2.0\\fstream\") cannot be referenced -- it is a deleted function",
"source": "C/C++",
"startLineNumber": 29,
"startColumn": 25,
"endLineNumber": 29,
"endColumn": 29
}]
I was able to get the same code working in a main function but I am trying to call a helper function for readability purposes.