M
Mug
hello
there i have a curious problem on fstream things,i tryed to read the
file with the unsigned char buffer,but compilater generate some
errors.
here's my program:
#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
int main(void)
{
unsigned char data_fetcher[2]; ;
/* if i declare char data_fetcher[2]; it will be ok but ...*/
char str[]="söfdsfsdfsd\n";
fstream data_file;
data_file.open("whatever",fstream:ut|fstream::in|fstream::app);
data_file.write(str,5*sizeof(char));
data_file.seekg(0,ios::beg);
data_file.read(data_fetcher,2*sizeof(unsigned char));
printf("display : %d %d \n",data_fetcher[0],data_fetcher[1]);
/* but here the value of data_fetcher[1] will be negative, this is
what i tryed to avoid */
data_file.close();
return 0;
}
I really need to know why i can't use it,i used to do those thing with
C function "read",it works perfectly,
sometime i deal with char value superior then 127,so i need to use
unsigned char here,can somebody help?
thx
Mug
there i have a curious problem on fstream things,i tryed to read the
file with the unsigned char buffer,but compilater generate some
errors.
here's my program:
#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
int main(void)
{
unsigned char data_fetcher[2]; ;
/* if i declare char data_fetcher[2]; it will be ok but ...*/
char str[]="söfdsfsdfsd\n";
fstream data_file;
data_file.open("whatever",fstream:ut|fstream::in|fstream::app);
data_file.write(str,5*sizeof(char));
data_file.seekg(0,ios::beg);
data_file.read(data_fetcher,2*sizeof(unsigned char));
printf("display : %d %d \n",data_fetcher[0],data_fetcher[1]);
/* but here the value of data_fetcher[1] will be negative, this is
what i tryed to avoid */
data_file.close();
return 0;
}
I really need to know why i can't use it,i used to do those thing with
C function "read",it works perfectly,
sometime i deal with char value superior then 127,so i need to use
unsigned char here,can somebody help?
thx
Mug