
On Monday 31 January 2005 10:00, Prabu Subroto wrote:
do you mean like this: " char mybuffer[]; fstream sumber("smb.conf"); if (!sumber){ cout << "Failed in opening the 'smb.conf' file\n"; exit(1); } sumber >> mybuffer; cout << mybuffer << endl; "?
Please tell me more details. Could you give me a very simple sample? yes, but you are not allocating space for mybuffer. You must declare a size. In the case below, I create a file, test.dat, but you could use smb.conf Nore that the >> operator reads a word. If you want to read a line, use the getline() member function. Here is an example, below. #include <iostream> #include <fstream> using std::cin; using std::cout; using std::cerr; using std::fstream; using std::endl; using std::ios; main () {
fstream file1; char mybuffer[512]; file1.open( "/etc/samba/smb.conf", ios::in); if (!file1) { cerr << "Unable to open test.dat." << endl; exit(1); } while( !file1.eof() ) { file1.getline(mybuffer, sizeof(mybuffer)); cout << mybuffer << endl; } file1.close(); } -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9