我有一个文件,我想要打印出它的内容,但我无法让我的功能正常工作,任何人都可以帮忙吗?
这是我的代码:
int main()
{
MenuText text;
string test = "Champion";
ofstream output("File.txt");
text.save(output);
fstream output ("File.txt");
text.load("File.txt");//This is an error.
text.print();
MenuText::MenuText()
{
mText = "Default";
}
MenuText :: MenuText(string text)
{
mText = text;
}
void MenuText::print()
{
cout<< "Story= " << mText<< endl;
cout<< endl;
}
void MenuText::save(ofstream& outFile)
{
outFile<< "/ . \ \____ \\ \\ _ -. "
//"/ /__ - \/\_______\\__\\__\ \"
"__\ /\ __ \ . \/_______//__//"
"__/\/__/ \ \ \_\ \ - ________ "
"___ ___ ______ \ \_____/ - /\ "
"__ \\ -.\ \\ ___\ \/_____/ ."
"\ \ \__\ \\ \-. \\ __\_ "
"- \ _\_______\\__\ `\___\\_____\ "
". \/_______//__/ /___//_____/ "<< mText<< endl;
cout<< endl;
outFile<< endl;
}
void MenuText::load(ifstream& inFile)
{
string garbage;
inFile>> garbage >> mText;
}
The errors are:
Error 1 error C2371: 'output' : redefinition; different basic types c:\users\conor\documents\college\c++ programming\marooned\marooned\mainapp.cpp 15 1 Marooned
Error 2 error C2664: 'MenuText::load' : cannot convert parameter 1 from 'const char [9]' to 'std::ifstream &' c:\users\conor\documents\college\c++ programming\marooned\marooned\mainapp.cpp 16 1 Marooned
答案 0 :(得分:2)