reading a file and display its content with cout
Dear my friend.
I want to make a linux server administrating tool ( I
am also a beginner in GNU C++).
if I open the file (smb.conf) with ifstream and try to
display its content with cout, but it does not display
its content only somewhat looksline only an address of
the variable in the memory.
like this:
"
psubroto@vh64:~/arsip/proyek/g++/BLiSS> ./liss
Choose the server you would like to administrate :
1. Samba Server
1
Samba Server Administrating Menu
--------------------------------
Workgroup name :bitp
nama workgroup-nya : bitp
0xbfffef64
psubroto@vh64:~/arsip/proyek/g++/BLiSS>
"
what is my mistake?
Here is my code underbelow.
=====
psubroto@vh64:~/arsip/proyek/g++/BLiSS> ls
bsamba.h bsamba.h~ liss liss.cpp liss.cpp~
smb.conf
psubroto@vh64:~/arsip/proyek/g++/BLiSS> cat bsamba.h
// Time-Stamp:<>
#include
On Monday 31 January 2005 03:52, Prabu Subroto wrote:
Here is my code underbelow. ===== psubroto@vh64:~/arsip/proyek/g++/BLiSS> ls bsamba.h bsamba.h~ liss liss.cpp liss.cpp~ smb.conf psubroto@vh64:~/arsip/proyek/g++/BLiSS> cat bsamba.h // Time-Stamp:<> #include
#include #include class bsamba { private:
public: void menu(); char bwg[]; void mengedit(); char Puffer[]; };
void bsamba::menu(){ cout << "Samba Server Administrating Menu\n"; cout << "--------------------------------\n" << endl; cout << "Workgroup name :"; cin >> bwg;
cout << "nama workgroup-nya : " << bwg << endl; fstream sumber("smb.conf"); if (!sumber){ cout << "Failed in opening the 'smb.conf' file\n"; exit(1); } cout << sumber << endl; }
void bsamba::mengedit(){
} psubroto@vh64:~/arsip/proyek/g++/BLiSS> cat liss.cpp // Time-Stamp: <> #include
#include #include "bsamba.h" int main(int argc, char **argv){ int svr; // for (;;){ cout << "Choose the server you would like to administrate :" << endl; cout << "1. Samba Server" << endl; cin >> svr;
switch (svr){ case 1: bsamba * sm = new bsamba(); sm->menu(); break; } } First, your header files are wrong. In the latest C++, they should be: #include <iostream> #include <fstream>
Next,
cout << sumber << endl; // This will display the file stream handle.
try:
char buf[512];
sumber >> buf;
cout << buf << endl;
I also strongly suggest you get yourself a good C++ book. This forum is not
here for learning how program in C++, it is here to help programmers with
problems.
--
Jerry Feldman
Dear Jerry.
OK, it's clear enough.
Thank you very much for your help. I really appreciate
your help.
--- Jerry Feldman
Here is my code underbelow. ===== psubroto@vh64:~/arsip/proyek/g++/BLiSS> ls bsamba.h bsamba.h~ liss liss.cpp liss.cpp~ smb.conf psubroto@vh64:~/arsip/proyek/g++/BLiSS> cat bsamba.h // Time-Stamp:<> #include
#include #include class bsamba { private:
public: void menu(); char bwg[]; void mengedit(); char Puffer[]; };
void bsamba::menu(){ cout << "Samba Server Administrating Menu\n"; cout << "--------------------------------\n" << endl; cout << "Workgroup name :"; cin >> bwg;
cout << "nama workgroup-nya : " << bwg << endl; fstream sumber("smb.conf"); if (!sumber){ cout << "Failed in opening the 'smb.conf' file\n"; exit(1); } cout << sumber << endl; }
void bsamba::mengedit(){
} psubroto@vh64:~/arsip/proyek/g++/BLiSS> cat
On Monday 31 January 2005 03:52, Prabu Subroto wrote: liss.cpp
// Time-Stamp: <> #include
#include #include "bsamba.h" int main(int argc, char **argv){ int svr; // for (;;){ cout << "Choose the server you would like to administrate :" << endl; cout << "1. Samba Server" << endl; cin >> svr;
switch (svr){ case 1: bsamba * sm = new bsamba(); sm->menu(); break; } } First, your header files are wrong. In the latest C++, they should be: #include <iostream> #include <fstream>
Next, cout << sumber << endl; // This will display the file stream handle. try: char buf[512]; sumber >> buf; cout << buf << endl;
I also strongly suggest you get yourself a good C++ book. This forum is not here for learning how program in C++, it is here to help programmers with problems.
-- Jerry Feldman
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 -- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
__________________________________ Do you Yahoo!? Yahoo! Mail - 250MB free storage. Do more. Manage less. http://info.mail.yahoo.com/mail_250
participants (2)
-
Jerry Feldman
-
Prabu Subroto