'\r' signs misssing

This is a discussion on '\r' signs misssing within the C++ Programming forums, part of the General Programming Boards category; I've recently noticed that if I use the tellg() function then it doesn't return the ammount of binary numbers in ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    160

    '\r' signs misssing

    I've recently noticed that if I use the tellg() function then it doesn't return the ammount of binary numbers in a file but the ammount of characters plus the '\r' signs.
    This happens no matter if I use ios::binary as flag or not.
    The problem is that if you then use read and put how long the file was into the second argument it doesn't add those '\r' by itself and still it demands them. All this put together means that you can't use this method unless it's a one line file.

    Code:
    int main () {
      char * buffer;
      long size;
      ifstream file (filename, ios::in|ios::binary|ios::ate);
      size = file.tellg();
      file.seekg (0, ios::beg);
      buffer = new char [size];
      file.read (buffer, size);
      file.close();
    
      cout << "the complete file is in a buffer";
    
      delete[] buffer;
      return 0;
    }
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    13

    binary numbers .?.

    Sorry, i don't really understand what you are refering to with 'binary numbers'...
    tellg() seems to return the length of the file in char sizes (for char actually length in bytes, for wchar_t the length in bytes / 2).
    In that view, a 110 bytes file contains 110 binary numbers, each one byte long and each representing a ascii character.

    What length do you need ?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    Both if I whant the characters and if I whant the length of the file in bytes.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    You have that length in characters.
    If you want the length in bytes, multiply that length by the length of one caracter:
    Code:
    size_in_bytes = number_of_characters * sizeof(ifstream::char_type);
    Teneniel
    "The Frenchmen and Russians possess the land, the British possess the sea, but we have over the airy realm of dreams command indisputably." ~ Heinrich Heine

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    okay, but I have to ask what wchar_t is? (I know I've seen it some where omnce before.)
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    For language sets that need more than a byte to represent a character, ie: Japanese
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convert UTF signs
    By Lebod in forum C Programming
    Replies: 2
    Last Post: 01-18-2009, 10:56 AM
  2. category of Math signs???
    By Vorkosigan in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2004, 04:00 PM
  3. What signs are there of that a girl is in love with you?
    By A_guy in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 05-21-2003, 07:48 AM
  4. How many signs can AnsiString handle
    By Zahl in forum C++ Programming
    Replies: 3
    Last Post: 11-15-2002, 03:35 PM
  5. Stupid people should wear SIGNS
    By C_Coder in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-15-2002, 08:49 AM

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