T
Tony Murphy
Strange problem, I read a file into a string using ifstream,
ostringstream and string and end part of the file is missing (file
size ~9.5kb, ~9k read). its a html file. using windows nt 4
------------- Not working right
----------------------------------------
ifstream file(filename.c_str());
if(!file) {
logError("FAILURE: Opening file %s",filename.c_str());
}
ostringstream buffer;
buffer << file.rdbuf();
string dataFromFile(buffer.str());
if(file.bad()) {
logError("Failed to read file %s, state=%d",filename,file.rdstate());
}
printf("%s",dataFromFile.c_str());
------------------------------------------------------------------------
then i print out the contents of file.rdbuf and the whole file is
printed to screen.
file.clear();
file.seekg(0, ios::beg);
cout << file.rdbuf() << endl;
-------------------------------------------------------------------------
this code only reads a portion of the file as well
file.clear();
file.seekg(0, ios::beg);
char l_buffer[10240];
memset(l_buffer,0,sizeof(l_buffer));
file.read( l_buffer, 10240 );
prinf("%s",l_buffer);
-------------------------------------------------------------------------
anyone know whats going on. if the file is smaller (~3kb), then i've
no problems. I tried c stdlib function fread(,,,) as well, and had
similar problem.
anyone point me to c++ faq and a good website. i have the c++
programming language by bjarne stroustrup, which is good, but need a
book with good examples & more of a tutorial rather than a reference.
thanks
ostringstream and string and end part of the file is missing (file
size ~9.5kb, ~9k read). its a html file. using windows nt 4
------------- Not working right
----------------------------------------
ifstream file(filename.c_str());
if(!file) {
logError("FAILURE: Opening file %s",filename.c_str());
}
ostringstream buffer;
buffer << file.rdbuf();
string dataFromFile(buffer.str());
if(file.bad()) {
logError("Failed to read file %s, state=%d",filename,file.rdstate());
}
printf("%s",dataFromFile.c_str());
------------------------------------------------------------------------
then i print out the contents of file.rdbuf and the whole file is
printed to screen.
file.clear();
file.seekg(0, ios::beg);
cout << file.rdbuf() << endl;
-------------------------------------------------------------------------
this code only reads a portion of the file as well
file.clear();
file.seekg(0, ios::beg);
char l_buffer[10240];
memset(l_buffer,0,sizeof(l_buffer));
file.read( l_buffer, 10240 );
prinf("%s",l_buffer);
-------------------------------------------------------------------------
anyone know whats going on. if the file is smaller (~3kb), then i've
no problems. I tried c stdlib function fread(,,,) as well, and had
similar problem.
anyone point me to c++ faq and a good website. i have the c++
programming language by bjarne stroustrup, which is good, but need a
book with good examples & more of a tutorial rather than a reference.
thanks