public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53626] New: move assignment for ifstream
@ 2012-06-10 19:46 mikhail_semenov at hotmail dot com
  2012-06-10 21:20 ` [Bug c++/53626] [C++11] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: mikhail_semenov at hotmail dot com @ 2012-06-10 19:46 UTC (permalink / raw)
  To: gcc-bugs

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;
}


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-22 13:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-10 19:46 [Bug c++/53626] New: move assignment for ifstream mikhail_semenov at hotmail dot com
2012-06-10 21:20 ` [Bug c++/53626] [C++11] " redi at gcc dot gnu.org
2013-06-22 19:11 ` [Bug libstdc++/53626] " paolo.carlini at oracle dot com
2014-09-19 10:58 ` redi at gcc dot gnu.org
2014-09-22 13:34 ` redi at gcc dot gnu.org
2014-09-22 13:45 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).