pointer to string/ file problem
Well, I have this problem: I want to read a file, get the size, and read all symbols. Then I do some stuff with the data and I`m trying to write it in file. But the program is adding another 65 symbols at the end of the file. The file is 6151 symbols long. Here is the code:
long file_size;
//here it reads the file_size - I`m sure it`s OK
unsigned char* input=new unsigned char[file_size]; //def. and init. the pointer
for(i=0; i<size; i++){
input[i]=in.get();
}
//and then do something to the data........
//then write it in file
for(int i=0;i<size;i++) out_file<<input[i];
So...any suggestions. Thanks!
Re: pointer to string/ file problem
Don't read/write character by character, because that's extremely slow. Read/write blocks, like:
Code:
long file_size;
//here it reads the file_size - I`m sure it`s OK
unsigned char* input=new unsigned char[file_size]; //def. and init. the pointer
in.read(input, file_size);
//and then do something to the data........
//then write it in file
out_file.write(input, file_size);
NOTE: How do you open the file? How do you retrieve the length of the file?
Re: pointer to string/ file problem
It`s OK. I`ve decided to use vector and it`s work.Thanks anyway.