Binary files

Greetings,

I am new to writing programs. I used examples form this web site to try to learn how to write in/out of files.

Program:

#include <iostream>
#include <fstream>


int main(void)
{
std::ifstream::pos_type memsize;
char *member;
std::string line;


//std::ifstream in("uans.cfg", std::ios::in|std::ios::binary|std::ios::ate);
std::ifstream in("uans.cfg", std::ios::in|std::ios::binary|std::ios::ate);
if (!in.is_open()) {
std::cout << "NO SUCH FILE" << std::endl;
return(1);
}
//std::cout << "FILE OPEN" << std::endl;
memsize = in.tellg();
member = new char [memsize];
in.seekg (0, std::ios::beg);
in.readsome(member, memsize);
in.seekg (0, std::ios::beg);
while (! in.eof() )
{
getline (in,line);
}
in.seekg (0, std::ios::beg);
std::cout <<"return by in.rdbuf[" << in.rdbuf() << "]" << std::endl;
std::cout << "return by member[" << member << "]" << std::endl;
std::cout << "return by line[" << line << "]" << std::endl;
in.close();



delete[] member;

return(0);;
}

Output:

return by in.rdbuf[localhost19000localhost88880x052362wwrny10]
return by member[localhost]
return by line[localhost19000localhost88880x052362wwrny10]

Why does not the member output return the full buffer information but the others do?

THKS
Vince
Topic archived. No new replies allowed.