Question
Hi, So I'm having an issue with the code that I've made for my Object Oriented Programming class. I'm trying to get through one of
Hi,
So I'm having an issue with the code that I've made for my Object Oriented Programming class. I'm trying to get through one of the challenges MyProgrammingLab 70046 to be exact. I keep getting errors:
Severity Code Description Project File Line Suppression State
Error (active) function "std::basic_ofstream<_Elem, _Traits>::basic_ofstream(const std::basic_ofstream<_Elem, _Traits>::_Myt &) [with _Elem=char, _Traits=std::char_traits]" (declared at line 1035 of "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\fstream") cannot be referenced -- it is a deleted function ConsoleApplication3 \\acad.dvuadmin.net\sce\HOMEDIR\D40724303\Documents\Visual Studio 2015\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp 127
Severity Code Description Project File Line Suppression State
Error (active) function "std::basic_ofstream<_Elem, _Traits>::basic_ofstream(const std::basic_ofstream<_Elem, _Traits>::_Myt &) [with _Elem=char, _Traits=std::char_traits]" (declared at line 1035 of "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\fstream") cannot be referenced -- it is a deleted function ConsoleApplication3 \\acad.dvuadmin.net\sce\HOMEDIR\D40724303\Documents\Visual Studio 2015\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp 139
Severity Code Description Project File Line Suppression State
Error (active) function "std::basic_ofstream<_Elem, _Traits>::basic_ofstream(const std::basic_ofstream<_Elem, _Traits>::_Myt &) [with _Elem=char, _Traits=std::char_traits]" (declared at line 1035 of "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\fstream") cannot be referenced -- it is a deleted function ConsoleApplication3 \\acad.dvuadmin.net\sce\HOMEDIR\D40724303\Documents\Visual Studio 2015\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp 150
Severity Code Description Project File Line Suppression State
Error C2280 'std::basic_ofstream>::basic_ofstream(const std::basic_ofstream> &)': attempting to reference a deleted function ConsoleApplication3 \\acad.dvuadmin.net\sce\homedir\d40724303\documents\visual studio 2015\consoleapplication3\consoleapplication3\consoleapplication3.cpp 127
I keep getting a red line under ofs in the main. I bolded the spots where I'm having the issue. Here's my code so far:
#include
#include
#include
using namespace std;
class Filter
{
private:
istream& is;
ostream& os;
public:
Filter(void) : is(cin), os(cout)
{
}
Filter(ifstream& ifs, ofstream& ofs) : is(ifs), os(ofs)
{
}
virtual char transform(char c) const = 0;
void doFilter(void)
{
char ch = '?';
while (is.peek() >-1);
{
ch = is.get();
os << transform(ch);
}
}
};
class Copy : public Filter
{
public:
Copy(void) : Filter()
{
}
Copy(ifstream& ifs, ofstream ofs) : Filter(ifs, ofs)
{
}
virtual char transform(char ch) const
{
return ch;
}
};
class Encr :public Filter
{
public:
Encr(void) : Filter()
{
}
Encr(ifstream& ifs, ofstream ofs) : Filter(ifs, ofs)
{
}
virtual char transform(char ch) const
{
if (ch >= 'A' && ch <= 'Z')
{
ch = ch - 65;
ch = ch + 13;
ch = ch % 26;
ch = ch + 65;
}
else if (ch >= 'a' && ch <= 'z')
{
ch = ch - 97;
ch = ch + 13;
ch = ch % 26;
ch = ch + 97;
}
else
{
return ch;
}
}
};
class Upper : public Filter
{
public:
Upper(void) : Filter()
{
}
Upper(ifstream& ifs, ofstream ofs) : Filter(ifs, ofs)
{
}
virtual char transform(char ch) const
{
if (ch >= 'a' && ch <= 'z')
return toupper(ch);
else
return ch;
}
};
int main(void)
{
Filter* fp;
string ifname = "input.txt";
string ofname;
ifstream ifs;
ofstream ofs;
ifs.open(ifname.c_str());
ofname = ifname + "_copy";
ofs.open(ofname.c_str());
if (ifs.is_open() && ofs.is_open())
{
fp = new Copy(ifs, ofs);
fp->doFilter();
ifs.close();
ofs.close();
delete fp;
}
ifs.open(ifname.c_str());
ofname = ifname + "_encr";
ofs.open(ofname.c_str());
if (ifs.is_open() && ofs.is_open())
{
fp = new Encr(ifs, ofs);
fp->doFilter();
ifs.close();
ofs.close();
delete fp;
}
ifs.open(ifname.c_str());
ofname = ifname + "_upper";
ofs.open(ofname.c_str());
if (ifs.is_open() && ofs.is_open())
{
fp = new Upper(ifs, ofs);
fp->doFilter();
ifs.close();
ofs.close();
delete fp;
}
return 0;
}
Any help would be greatly appreciated!
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