This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53626] New: move assignment for ifstream
- From: "mikhail_semenov at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 10 Jun 2012 19:45:56 +0000
- Subject: [Bug c++/53626] New: move assignment for ifstream
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53626
Bug #: 53626
Summary: move assignment for ifstream
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mikhail_semenov@hotmail.com
Created attachment 27599
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27599
The program
The move assignment operator should be provided for ifstream.
The following program fails to compile. It should print out the contents of a
text file, whose first line starts with "My File".
#include <iostream>
#include <string>
#include <fstream>
std::ifstream OpenMyFile(const std::string& filename)
{
std::ifstream file(filename);
if (!file.good())
{
file.close();
return file;
}
std::string s;
std::getline(file, s);
if (s.substr(0,7) != "My File")
{
file.close();
file.setstate(std::ios_base::failbit);
return file;
}
return file;
}
int main(int count, char *args[])
{
if (count < 2)
{
std::cout << "Incorrect number of parameters" << std::endl;
return -1;
}
std::ifstream myFile = OpenMyFile(args[1]);
if (myFile.good())
{
while (!myFile.eof())
{
std::string s;
std::getline(myFile,s);
std::cout << s << std::endl;
}
}
else
{
std::cout << "*** FILE ERROR ***" << std::endl;
}
return 0;
}