read specific number of chars from stream

This is a discussion on read specific number of chars from stream within the C++ Programming forums, part of the General Programming Boards category; Is there any function or way to read from a stream a specific number of characters and flush the stream ...

  1. #1
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142

    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,468
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 04:46 AM
  3. read data
    By in_need in forum C Programming
    Replies: 2
    Last Post: 10-30-2001, 07: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21