CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    57

    How to get size of non ASCII formatted (char *)

    I want to get a file and store it in a character array. The file isn't ASCII formatted so I can't use strlen(). Is there any other way to get the size of the array?

  2. #2
    Join Date
    Oct 2005
    Posts
    526

    Re: How to get size of non ASCII formatted (char *)

    you haven't told what format is .UTF8 ? UCS2 ? there should be some corresponding functions to get the length .

  3. #3
    Join Date
    Aug 2007
    Posts
    858

    Re: How to get size of non ASCII formatted (char *)

    If you're treating the file as one big chunk of data, just use fstream's methods to get the size before you read it.

    Code:
    std::ifstream file("somefile.dat", std:ios::binary);
    std::vector<char> buffer;
    
    file.seekg(0, std::ios::end);
    buffer.resize(file.tellg());
    file.seekg(0, std::ios::beg);
    
    file.read(&buffer[0], buffer.size());
    
    ...

  4. #4
    Join Date
    Sep 2009
    Posts
    57

    Re: How to get size of non ASCII formatted (char *)

    Quote Originally Posted by Speedo View Post
    If you're treating the file as one big chunk of data, just use fstream's methods to get the size before you read it.

    Code:
    std::ifstream file("somefile.dat", std:ios::binary);
    std::vector<char> buffer;
    
    file.seekg(0, std::ios::end);
    buffer.resize(file.tellg());
    file.seekg(0, std::ios::beg);
    
    file.read(&buffer[0], buffer.size());
    
    ...
    Thanks for helping speedo. Now I understood that I have to use the file.seekg() to go to the end of the file and file.tellg() to get the size.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured