|
From: Gerald H. <gl...@we...> - 2005-02-18 07:32:11
|
Hello Everyone This is my first post and i am just starting c++. So if you could help me i would appreciate it. I am a vb programmer wanting to go into c++. My first visual basic program was just a small calculate with 2 text boxes and a Button, now when you enter in an integer in the 2 text boxes and click on the Button it will multply those and give the answer in a message box. I am asking if someone can please show me how to do that in a c++ app not in the concoll way. It would be nice if soneone can do it it Microsoft visual c++. Regards Gerald Humphreys |
|
From: Jakob E. <mai...@ko...> - 2005-02-18 11:52:34
|
Ok, here is the thing. I'm trying to read from a file. But for some reason the entire file wont = =20 read. It's really strange becaus fstream::read() is suposed to read all the dat= a =20 at once (unlike readsome() ) Has any one of you ever run in to this problem. The source: //get the filesize=09 file.seekg( 0,ios_base::end ); file_size =3D file.tellg(); file.seekg( 0,ios_base::beg ); p_buffer =3D new char[file_size]; cout << "file size:" << file_size<<endl; file.read(p_buffer, file_size); cout << "gcount: "<< file.gcount()<<endl; ap_socket->send(p_buffer, file_size); delete p_buffer; the output: file size:6090 gcount: 5 |
|
From: Gerson L. <ja...@ya...> - 2005-02-18 17:04:54
|
Hi all!
Iv'e seen you code, and it's almost axactly like mine!
That has always worked for me, so, I will just show you the little differences, maybe one of them brings your code to life!
int main(int argc, char* argv[]) // classic
{
//just printing the parameter list
cout << "running " << argv[0] << "\nwith parameters:\n";
for(int i = 1; i < argc; i++) cout << argv[i] << " ";
if(argc == 2){
cout << "\nTrying to open file " << argv[1] << endl;
ifstream BMP(argv[1], ios::in);
long FileSize = 0;
if(!BMP){
cout << "Could not open file\n";
return 0;
}else{
cout << "File opened\n";
BMP.seekg(0,ios::end); FileSize = BMP.tellg(); BMP.seekg(0, ios::beg);
p_buffer = new char[FileSize];// careful if you do it this way!
// supose p_buffer is of type char*
cout << "File size: " << FileSize << endl;
BMP.read( p_buffer, FileSize);
////// the rest of code goes here
Now: the differences:
You didn't show how you opened the file, so, may be there a "little thing"
I open it like this:
ifstream BMP(argv[1], ios::in);
or:
ifstream BMP("fichero.txt", ios::in);
the important for me here is: I use ifstream if Im gonna read the file, ofstream for writing. ( fstream ONLY if i need to read/write to the same file in a single operation)
the modes tha I use are: ios::in, ios::out, ios::app, ios::trunc, ios::bin
Then, the way of retrieving the file size is tha same, except for I use only 'ios' instead of ios_'base'.
I don't think that to be so important, but, exist tha posibility that there is some inheritance theme here, using just ios::whatever has allways worked fine for me.
The rest of thing seem to be just fine!!
So , I can only say tha the trouble seems to be with the opening of the file.
In my few expreriences, if you read a file to the end, I mean, if you read "all the file" once, you'll not be able to read again, even moving the read pointer ( i.e. seekg(0, ios::beg ), unless you close the file and re-open it. Is that happening to you? I recomend to read all the file, and close it, so if you need it later, you have it in RAM, you can modify the contens of the file in RAM and then use ofstream to replace the contens of the file to actualize it.
Im a very satisfied user of fstream, i can even read binary files with it, like bitmap files or .mp3 files. so I can tell fstream is powerful. So if you can't resolve, tell me more about your code.
Notes: I use Dev C++ 4.1
Question: what are you doing with this? ::: ap_socket->send(p_buffer, file_size);
is it networking stuff?
Jakob EKlund <mai...@ko...> wrote:
Ok, here is the thing.
I'm trying to read from a file. But for some reason the entire file wont
read.
It's really strange becaus fstream::read() is suposed to read all the data
at once (unlike readsome() )
Has any one of you ever run in to this problem.
The source:
//get the filesize
file.seekg( 0,ios_base::end );
file_size = file.tellg();
file.seekg( 0,ios_base::beg );
p_buffer = new char[file_size];
cout << "file size:" << file_size<
file.read(p_buffer, file_size);
cout << "gcount: "<< file.gcount()<
ap_socket->send(p_buffer, file_size);
delete p_buffer;
the output:
file size:6090
gcount: 5
---------------------------------
|
|
From: Alfred P. R. <al...@ya...> - 2005-02-18 20:02:06
|
The other thing is file mode, text vs. binary. If you open the file in text mode, and you get an EOF character, the read will terminate, however you can read lines of text. In binary mode, EOF is just another character. I forget offhand which is the default open mode. The sites of pertinence are Microsoft's header library documentation: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcstdlib/html/vclrfcpluspluslibraryoverview.asp and C++ I/O: http://www.cppreference.com/cppio/ --- Gerson Lara <ja...@ya...> wrote: <snip> > So , I can only say tha the trouble seems to be with the opening of > the file. > In my few expreriences, if you read a file to the end, I mean, if you > read "all the file" once, you'll not be able to read again, even > moving the read pointer ( i.e. seekg(0, ios::beg ), unless you close > the file and re-open it. Is that happening to you? I recomend to read > all the file, and close it, so if you need it later, you have it in > RAM, you can modify the contens of the file in RAM and then use > ofstream to replace the contens of the file to actualize it. > > Im a very satisfied user of fstream, i can even read binary files > with it, like bitmap files or .mp3 files. so I can tell fstream is > powerful. So if you can't resolve, tell me more about your code. <snip> ===== Alfred P. Reaud |
|
From: Jakob E. <mai...@ko...> - 2005-02-18 13:10:22
|
GUI programming in C++ is alot harder than in VB(atleast that's what I've= =20 heard, I've never used vb). A good startingpoint is probably this site: http://www.winprog.org/tutorial/ Den 2005-02-18 09:44:14 skrev Gerald Humphreys <gl...@we...>: > Hello Everyone > > This is my first post and i am just starting c++. So if you could help = =20 > me i > would appreciate it. I am a vb programmer wanting to go into c++. My =20 > first > visual basic program was just a small calculate with 2 text boxes and a > Button, now when you enter in an integer in the 2 text boxes and click = =20 > on the > Button it will multply those and give the answer in a message box. I am > asking if someone can please show me how to do that in a c++ app not in= =20 > the > concoll way. It would be nice if soneone can do it it Microsoft visual = =20 > c++. > > Regards > Gerald Humphreys > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users= . > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=3D6595&alloc_id=3D14396&op=3Dclick > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Per W. <pw...@ia...> - 2005-02-18 14:59:39
|
This list is - as is quite obvious from the name - for users of Dev-C++, i.e. a free IDE alternative for use instead of Visual C++. Most code discussed here is because of this about the use of different free libraries together with Dev-C++. One very good framework for platform-independant code is wxWidgets. It contains a large number of nice example programs - windows applications, graphics, networking, etc. The wxWidgets library is possible to use with most compilers - including VC++. Information, examples etc are available at: http://www.wxwidgets.org/ /Per W On Fri, 18 Feb 2005, Gerald Humphreys wrote: > Hello Everyone > > This is my first post and i am just starting c++. So if you could help me i > would appreciate it. I am a vb programmer wanting to go into c++. My first > visual basic program was just a small calculate with 2 text boxes and a > Button, now when you enter in an integer in the 2 text boxes and click on the > Button it will multply those and give the answer in a message box. I am > asking if someone can please show me how to do that in a c++ app not in the > concoll way. It would be nice if soneone can do it it Microsoft visual c++. > > Regards > Gerald Humphreys |