Thread: read specific number of chars from stream

  1. #1
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154

    read specific number of chars from stream

    Is there any function or way to read from a stream a specific number of characters and flush the stream ?

    ex.
    Need to read only 6 characters into string test

    Input : blablablablabla
    test : blabla


    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Use a for loop, reading in 1 char at a time into the string, or read in the entire string and truncate it to the desired length.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    http://msdn2.microsoft.com/en-us/lib...69(VS.60).aspx - read could specify nCount
    http://msdn2.microsoft.com/en-us/lib...60(VS.60).aspx - get could specify nCount
    http://msdn2.microsoft.com/en-us/lib...61(VS.60).aspx - getline could specify nCount

    http://msdn2.microsoft.com/en-us/lib...62(VS.60).aspx - ignore - could specify ncount and delimiter

    Are you sure you have read istream spec and havn't found anything matching your needs?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  2. unknown number of chars
    By Garfield in forum C Programming
    Replies: 16
    Last Post: 10-31-2001, 05:46 AM
  3. read data
    By in_need in forum C Programming
    Replies: 2
    Last Post: 10-30-2001, 08:10 AM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM