Mail Archives: djgpp/1998/05/16/11:00:41
From: | "jan malina" <jan DOT malina AT ping DOT be>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: File i/o , strings in c++ help a beginner.
|
Date: | Sat, 16 May 1998 16:59:35 +0200
|
Organization: | EUnet Belgium, Leuven, Belgium
|
Lines: | 79
|
Message-ID: | <6jk9l9$5be$1@news3.Belgium.EU.net>
|
References: | <01bd7e3b$310abf00$LocalHost AT default>
|
NNTP-Posting-Host: | dialup007.gent.eunet.be
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
jo heeft geschreven in bericht <01bd7e3b$310abf00$LocalHost AT default>...
>I'm slowly learning c++. Have gone through some c tutorials etc and am
>currently going through a few c++ ones.
>
>Writing a little program of my own to learn along the way. Started
>doing it in c and would now like to convert it to c++.
>
>It involves reading from a text file, looking for certain words and
>extracting dates, numbers etc..
>
>In C it uses:
>fp1 = fopen("modemlog.txt", "r");
> if (fp1 == NULL)
> {
> printf("File failed open");
> exit (EXIT_FAILURE);
> }
Noooooooooooooo, try this:
ifstream fp1;
fp1.open("modemlog.txt", ios::nocreate);
if (!fp1) { cout << "File failed open\n"; exit(EXIT_FAILURE); }
>
>to open the file for reading, how do I change this to the c++ way?
>
>c = fgets(line, 100, fp1);
> if (c != NULL)
> {
> ...loop here
> }
while (c != EOF) {
c=fp1.get();
}
fp1.close();
>
>line is a char array of 100 elements. Is there a similar c++ 'fgets'
>command?
>If not how do I change the above snippet to c++? Would like to keep the
>checking for the end of file in there too.
>
>Also it uses 'strstr' to check if a certain word is in the 'line'
>array, is there a similar c++ function for this?
>
>and similar c++ alternatives to :
>strcmp
>strcpy
>atoi
>atof
>isspace
No, use th c one's
>
>I am using djgpp under win95. I've found a libc reference in win help
>file format. Is there a libc++ ref that I could download somewhere?
>
>Would also appreciate any good c++ reference sites, I have a couple of
>c++ tutorials but they don't really cover file I/O or string handling
>in depth, so would appreciate any 'simple' source code, docs, tutes etc
>for this sort of thing. I'm an absolute beginner so the simpler the
>better.
>
>Thanks for your time.
>
>remove no spam from email
>
>--
>------------------------------------------------------------------------
>
>
>
>
>
>
- Raw text -