Thread: readsome() doesn't work

  1. #1
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA

    readsome() doesn't work

    Maybe it's just me again, but readsome never seems to actually read anything, and always returns 0. For example:
    #include <iostream>
    #include <fstream>
    int main()
      std::ifstream in("test.txt"); //test.txt exists and contains text
      if (!in.good())
         std::cout<<"Error opening file!";
      char buf[11]={0};
      while (true)
        int count = in.readsome(buf,10);
        std::cout<<count<<' '<<buf<<std::endl;
    If I run that example, I get no output at all (it breaks the first time the loop runs). This isn't really a problem (I can just use read() and gcount()), but I was wondering if it's really broken, or if I'm somehow doing something wrong (using VS .NET 2003 btw).
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  2. #2
    Registered User
    Join Date
    Apr 2003
    readsome() doesn't work on VC++ 6 either. It didn't appear on the popup member list after I typed "in.", so I don't think it's supported. Supposedly readsome() examines an iostream object's "internal buffer" so that you can read from the internal buffer before the read operation, which is filling the buffer, finishes. Apparently under the C++ standards, compilers are allowed to return 0 from readsome() to prevent you from mucking about inside the iostream object.

    Try read() and gcount() instead.
    Last edited by 7stud; 11-03-2005 at 01:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM