I have a problem and I dont know how to solve it. The issue is:
char * ary = new Char[]; ifstream fle; fle.open(1.txt, ios_base::binary); fle.seekg(fle.end); long count = fle.tellg(); fle.seek(fle.beg); here is the problem: File 1.txt contains: Hello world!.
when I execute:
ary = new char(count); fle.read(ary, count); the ary filled like this: Hello world! @T#^@$@FF(garbage)
The file is ookay nothing inside it only what is above.
Platform: Win 7, VS 2012
Any idea how to solve this issue. (Solved)
(Problem 2) Now I am facing another problem, the fle.read sometimes read more than the size i gave. For Example if i passed like fle.read(buffer, 1000) it ends in some cases (strlen(buffer) = 1500. How can i solve this?
Regards,
ary = new char(count); memset(ary, 0, count); fle.read(ary,count);, for memset, you will also need#include <string.h>if you dont already have it.oin it.memsetrequires<string.h>or<cstring>new char(..)creates a single char not an array! andnew char[]is pointless! (didn't even know it would compile).