|
-
September 13th, 2009, 06:46 AM
#1
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?
-
September 13th, 2009, 10:09 AM
#2
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 .
-
September 13th, 2009, 02:19 PM
#3
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());
...
-
September 14th, 2009, 09:00 AM
#4
Re: How to get size of non ASCII formatted (char *)
 Originally Posted by Speedo
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|